Fixed getChildRelativeToDir for multi-dir checks

This commit is contained in:
nathan 2016-12-29 02:32:55 +01:00
parent 1ba2cb8ba8
commit ab79616ca2

View File

@ -952,6 +952,8 @@ class FileUtil {
* Gets the relative path of a file to a specific directory in it's hierarchy. * Gets the relative path of a file to a specific directory in it's hierarchy.
* <p/> * <p/>
* For example: getChildRelativeToDir("/a/b/c/d/e.bah", "c") -> "d/e.bah" * For example: getChildRelativeToDir("/a/b/c/d/e.bah", "c") -> "d/e.bah"
*
* @return null if there is no child
*/ */
public static public static
String getChildRelativeToDir(String fileName, String dirInHeirarchy) { String getChildRelativeToDir(String fileName, String dirInHeirarchy) {
@ -967,7 +969,7 @@ class FileUtil {
* <p/> * <p/>
* For example: getChildRelativeToDir("/a/b/c/d/e.bah", "c") -> "d/e.bah" * For example: getChildRelativeToDir("/a/b/c/d/e.bah", "c") -> "d/e.bah"
* *
* @return null if it cannot be found * @return null if there is no child
*/ */
public static public static
String getChildRelativeToDir(File file, String dirInHeirarchy) { String getChildRelativeToDir(File file, String dirInHeirarchy) {
@ -1010,9 +1012,13 @@ class FileUtil {
if (parentName.equals(split[splitIndex])) { if (parentName.equals(split[splitIndex])) {
splitIndex--; splitIndex--;
if (splitIndex < 0) { if (splitIndex < 0) {
parent = parent.getParentFile(); // this means the ENTIRE path matched
parentName = parent.getAbsolutePath(); if (absolutePath.length() == dirInHeirarchy.length()) {
return absolutePath.substring(parentName.length() + 1); return null;
}
// +1 to account for the separator char
return absolutePath.substring(dirInHeirarchy.length() + 1, absolutePath.length());
} }
} }
else { else {