diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-08 22:39:59 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-08 22:39:59 -0300 |
| commit | c82e3b3b2de0633317ec8fc85925e91422820597 (patch) | |
| tree | 96567416ce23c5ce85601f9cedc3a94bb1c55cba /base/src/main/java/bjc/utils/funcutils/FileUtils.java | |
| parent | b3ac1c8690c3e14c879913e5dcc03a5f5e14876e (diff) | |
Start splitting into maven modules
Diffstat (limited to 'base/src/main/java/bjc/utils/funcutils/FileUtils.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/funcutils/FileUtils.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/funcutils/FileUtils.java b/base/src/main/java/bjc/utils/funcutils/FileUtils.java new file mode 100644 index 0000000..87199b1 --- /dev/null +++ b/base/src/main/java/bjc/utils/funcutils/FileUtils.java @@ -0,0 +1,40 @@ +package bjc.utils.funcutils; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.function.BiPredicate; + +/** + * Utilities for doing things with files + * + * @author ben + * + */ +public class FileUtils { + /** + * Traverse a directory recursively. This is a depth-first traversal + * + * + * @param root + * The directory to start the traversal at + * @param predicate + * The predicate to determine whether or not to traverse + * a directory + * @param action + * The action to invoke upon each file in the directory. + * Returning true means to continue the traversal, + * returning false stops it + * @throws IOException + * if the walk throws an exception + * + * TODO If it becomes necessary, write another overload + * for this with all the buttons and knobs from + * walkFileTree + */ + public static void traverseDirectory(final Path root, final BiPredicate<Path, BasicFileAttributes> predicate, + final BiPredicate<Path, BasicFileAttributes> action) throws IOException { + Files.walkFileTree(root, new FunctionalFileVisitor(predicate, action)); + } +} |
