blob: ea5c72ebd716b82db983464bcc486cf0f1c6e581 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
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 traversalPredicate
* The predicate to determine whether or not to traverse a
* directory
* @param traversalAction
* 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(Path root,
BiPredicate<Path, BasicFileAttributes> traversalPredicate,
BiPredicate<Path, BasicFileAttributes> traversalAction)
throws IOException {
Files.walkFileTree(root, new FunctionalFileVisitor(
traversalPredicate, traversalAction));
}
}
|