Make a non-recursive fileWalker

This commit is contained in:
Frank 2021-08-17 09:53:04 +02:00
parent 742ea56e34
commit 6837c7d081

View file

@ -24,7 +24,6 @@ public class PathUtil {
return child.equals(parent); return child.equals(parent);
} }
/** /**
* A simple directory walker that ignores dot-files * A simple directory walker that ignores dot-files
* *
@ -33,6 +32,18 @@ public class PathUtil {
* for each visited file * for each visited file
*/ */
public static void fileWalker(File path, Consumer<Path> pathConsumer) { public static void fileWalker(File path, Consumer<Path> pathConsumer) {
fileWalker(path, true, pathConsumer);
}
/**
* A simple directory walker that ignores dot-files
*
* @param path The path where you want to start
* @param recursive if {@code false}, only the {@code path} is traversed
* @param pathConsumer The consumer called for each valid file. The consumer will get an absolute {@link Path}-Object
* for each visited file
*/
public static void fileWalker(File path, boolean recursive, Consumer<Path> pathConsumer) {
if (!path.exists()) return; if (!path.exists()) return;
for (final File f : path.listFiles()) { for (final File f : path.listFiles()) {
if (f.getName() if (f.getName()