W3cubDocs

/Kotlin

FileTreeWalk

Platform and version requirements: JVM (1.0)
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

Platform and version requirements: JVM (1.0)

iterator

Returns an iterator walking through files.

fun iterator(): Iterator<File>
Platform and version requirements: JVM (1.0)

maxDepth

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

fun maxDepth(depth: Int): FileTreeWalk
Platform and version requirements: JVM (1.0)

onEnter

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

fun onEnter(function: (File) -> Boolean): FileTreeWalk
Platform and version requirements: JVM (1.0)

onFail

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

fun onFail(
    function: (File, IOException) -> Unit
): FileTreeWalk
Platform and version requirements: JVM (1.0)

onLeave

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

fun onLeave(function: (File) -> Unit): FileTreeWalk

Extension Functions

Platform and version requirements: JVM (1.0)

filterIsInstance

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

fun <R> Sequence<*>.filterIsInstance(
    klass: Class<R>
): Sequence<R>
Platform and version requirements: JVM (1.0)

filterIsInstanceTo

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

fun <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(
    destination: C, 
    klass: Class<R>
): C
Platform and version requirements: JVM (1.4)

sumOf

Returns the sum of all values produced by selector function applied to each element in the sequence.

fun <T> Sequence<T>.sumOf(
    selector: (T) -> BigDecimal
): BigDecimal
fun <T> Sequence<T>.sumOf(
    selector: (T) -> BigInteger
): BigInteger
Platform and version requirements: JVM (1.0)

toSortedSet

Returns a new SortedSet of all elements.

fun <T> Sequence<T>.toSortedSet(
    comparator: Comparator<in T>
): SortedSet<T>

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/-file-tree-walk/index.html