public class FileTreeWalk extends Object implements Iterable<File>
Use File.walk, File.walkTopDown or File.walkBottomUp extension
methods to instantiate a FileTreeWalk instance.
If the file path given is just a file, walker iterates only it. If the file path given does not exist, walker iterates nothing, i.e., it's equivalent to an empty sequence.
| Modifier and Type | Class and Description |
|---|---|
static class |
FileTreeWalk.FileWalkDirection
An enumeration to describe possible walk directions.
|
| Constructor and Description |
|---|
FileTreeWalk(File start) |
FileTreeWalk(File start,
FileTreeWalk.FileWalkDirection direction) |
FileTreeWalk(File start,
FileTreeWalk.FileWalkDirection direction,
java.util.function.Function<File,Boolean> onEnter,
java.util.function.Consumer<File> onLeave,
java.util.function.BiConsumer<File,IOException> onFail,
int maxDepth) |
| Modifier and Type | Method and Description |
|---|---|
Iterator<File> |
iterator()
Returns an iterator walking through files.
|
FileTreeWalk |
maxDepth(int depth)
Sets the maximum [depth] of a directory tree to traverse.
|
FileTreeWalk |
onEnter(java.util.function.Function<File,Boolean> function)
Sets a predicate [function], that is called on any entered directory before its files are visited
and before it is visited itself.
|
FileTreeWalk |
onFail(java.util.function.BiConsumer<File,IOException> function)
Set a callback [function], that is called on a directory when it's impossible to get its file list.
|
FileTreeWalk |
onLeave(java.util.function.Consumer<File> function)
Sets a callback [function], that is called on any left directory after its files are visited and after it is visited itself.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic FileTreeWalk(File start, FileTreeWalk.FileWalkDirection direction, java.util.function.Function<File,Boolean> onEnter, java.util.function.Consumer<File> onLeave, java.util.function.BiConsumer<File,IOException> onFail, int maxDepth)
public FileTreeWalk(File start, FileTreeWalk.FileWalkDirection direction)
public FileTreeWalk(File start)
public FileTreeWalk onEnter(java.util.function.Function<File,Boolean> function)
If the [function] returns `false` the directory is not entered and neither it nor its files are visited.
public FileTreeWalk onLeave(java.util.function.Consumer<File> function)
public FileTreeWalk onFail(java.util.function.BiConsumer<File,IOException> function)
[onEnter] and [onLeave] callback functions are called even in this case.
public FileTreeWalk maxDepth(int depth)
The value must be positive and [Int.MAX_VALUE] is used to specify an unlimited depth.
With a value of 1, walker visits only the origin directory and all its immediate children, with a value of 2 also grandchildren, etc.
Copyright © 2020. All rights reserved.