FileTreeWalk

class FileTreeWalk : Sequence<File>

This class is intended to implement different file traversal methods. It allows to iterate through all files inside a given directory.

Use File.walk, File.walkTopDown or File.walkBottomUp extension functions 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.

Functions

iterator
Link copied to clipboard
open operator override fun iterator(): Iterator<File>

Returns an iterator walking through files.

maxDepth
Link copied to clipboard
fun maxDepth(depth: Int): FileTreeWalk

Sets the maximum depth of a directory tree to traverse. By default there is no limit.

onEnter
Link copied to clipboard
fun onEnter(function: (File) -> Boolean): FileTreeWalk

Sets a predicate function, that is called on any entered directory before its files are visited and before it is visited itself.

onFail
Link copied to clipboard
fun onFail(function: (File, IOException) -> Unit): FileTreeWalk

Set a callback function, that is called on a directory when it's impossible to get its file list.

onLeave
Link copied to clipboard
fun onLeave(function: (File) -> Unit): FileTreeWalk

Sets a callback function, that is called on any left directory after its files are visited and after it is visited itself.