FileTreeWalk

class FileTreeWalk : Sequence<File> (source)

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.

Since Kotlin

1.0

Functions

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

Returns an iterator walking through files.

Since Kotlin 1.0
Link copied to clipboard

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

Since Kotlin 1.0
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.

Since Kotlin 1.0
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.

Since Kotlin 1.0
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.

Since Kotlin 1.0

Extensions

Link copied to clipboard
fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R>

Returns a sequence containing all elements that are instances of specified class.

Since Kotlin 1.0
Link copied to clipboard
fun <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C

Appends all elements that are instances of specified class to the given destination.

Since Kotlin 1.0
Link copied to clipboard
fun <T : Comparable<T>> Sequence<T>.max(): T?
Since Kotlin 1.0
Link copied to clipboard
inline fun <T, R : Comparable<R>> Sequence<T>.maxBy(selector: (T) -> R): T?
Since Kotlin 1.0
Link copied to clipboard
fun <T> Sequence<T>.maxWith(comparator: Comparator<in T>): T?
Since Kotlin 1.0
Link copied to clipboard
fun <T : Comparable<T>> Sequence<T>.min(): T?
Since Kotlin 1.0
Link copied to clipboard
inline fun <T, R : Comparable<R>> Sequence<T>.minBy(selector: (T) -> R): T?
Since Kotlin 1.0
Link copied to clipboard
fun <T> Sequence<T>.minWith(comparator: Comparator<in T>): T?
Since Kotlin 1.0
Link copied to clipboard
fun <T : Comparable<T>> Sequence<T>.toSortedSet(): SortedSet<T>
fun <T> Sequence<T>.toSortedSet(comparator: Comparator<in T>): SortedSet<T>

Returns a new SortedSet of all elements.

Since Kotlin 1.0