Skip to content

Commit d1075ff

Browse files
committed
Simplify FileUtil.isFileInDirectory().
1 parent 44d6cda commit d1075ff

1 file changed

Lines changed: 1 addition & 10 deletions

File tree

util/src/main/java/nl/inl/util/FileUtil.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,7 @@ public void process(File f) {
170170
* @return true if the file is in the directory or one of its subdirectories, false otherwise
171171
*/
172172
public static boolean isFileInDirectory(File file, File directory) {
173-
File parent = file.getParentFile();
174-
boolean ok = false;
175-
while (parent != null) {
176-
if (parent.equals(directory)) {
177-
ok = true;
178-
break;
179-
}
180-
parent = parent.getParentFile();
181-
}
182-
return ok;
173+
return file.toPath().normalize().startsWith(directory.toPath().normalize());
183174
}
184175

185176
/**

0 commit comments

Comments
 (0)