List files recursively in Kotlin
to list files in a directory with kotlin, i used list() and listFiles() functions:
File("/tmp").list().forEach { println(it) }
File("/tmp").listFiles().forEach { println(it) }
but, how can i list files recursively?
Use one of .walk(...)
, .walkBottomUp()
or .walkTopDown()
extensions for File
, which differ only in the order in which the files appear and all produce a FileTreeWalk
, that implements Sequence<File>
:
File("/tmp").walkTopDown().forEach { println(it) }