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,
Function<File,Boolean> onEnter,
Consumer<File> onLeave,
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(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(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(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, emptyArray, equals, finalize, getClass, hashCode, jailbreak, notify, notifyAll, toString, wait, wait, waitcount, count, distinctBy, distinctList, filterIndexedTo, filterIndexedToList, filterNotTo, filterNotToList, filterTo, filterToList, first, first, firstOrNull, firstOrNull, flatMap, flatMapTo, fold, forEach, forEachIndexed, indexOfFirst, indexOfLast, intersect, joinTo, joinToString, last, last, lastOrNull, lastOrNull, mapIndexed, mapIndexedNotNull, mapIndexedNotNullTo, mapIndexedNotNullToList, mapIndexedTo, mapIndexedToList, mapNotNull, mapNotNullTo, mapNotNullToList, mapTo, mapToList, maxWith, minWith, partition, reversed, single, single, singleOrNull, singleOrNull, spliterator, subList, subList, subtract, toList, toSet, unionpublic FileTreeWalk(File start, FileTreeWalk.FileWalkDirection direction, Function<File,Boolean> onEnter, Consumer<File> onLeave, BiConsumer<File,IOException> onFail, int maxDepth)
public FileTreeWalk(File start, FileTreeWalk.FileWalkDirection direction)
public FileTreeWalk(File start)
public FileTreeWalk onEnter(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(Consumer<File> function)
public FileTreeWalk onFail(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 © 2024. All rights reserved.