Walking the file tree in Kotlin

fun main() {
    File(".").walkTopDown().forEach { println(it) } // Walk functions all return a sequence of files. This starts at the root directory and navigates to each branch, listing as it goes (directories before files).
    // Also walkBottomUp()
    println("======")
    // We can treat the output like a sequence and filter out the results we want:
    File(".").walkTopDown()
        .filter { it.name.endsWith(".kt") }
        .forEach { println(it) }
    // If you want to do something before or after entering the directory you can use the onEnter and onLeave
    // onEnter takes a lambda that returns a Boolean - if false, is skipped
}