blob: 35a6b3d230f1ee6e8ef918bcdac77e3a7c3ee63b (
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
|
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(Path root, BiPredicate<Path, BasicFileAttributes> predicate,
BiPredicate<Path, BasicFileAttributes> action) throws IOException {
Files.walkFileTree(root, new FunctionalFileVisitor(predicate, action));
}
}
|