visitFileTree
Visits this directory and all its content with the specified visitor.
The traversal is in depth-first order and starts at this directory. The specified visitor is invoked on each file encountered.
Since Kotlin
1.7Parameters
the FileVisitor that receives callbacks.
the maximum depth to traverse. By default, there is no limit.
specifies whether to follow symbolic links, false
by default.
See also
Visits this directory and all its content with the FileVisitor defined in builderAction.
This function works the same as Path.visitFileTree. It is introduced to streamline the cases when a FileVisitor is created only to be immediately used for a file tree traversal. The trailing lambda builderAction is passed to fileVisitor to get the file visitor.
Example:
projectDirectory.visitFileTree {
onPreVisitDirectory { directory, _ ->
if (directory.name == "build") {
directory.toFile().deleteRecursively()
FileVisitResult.SKIP_SUBTREE
} else {
FileVisitResult.CONTINUE
}
}
onVisitFile { file, _ ->
if (file.extension == "class") {
file.deleteExisting()
}
FileVisitResult.CONTINUE
}
}
Since Kotlin
1.7Parameters
the maximum depth to traverse. By default, there is no limit.
specifies whether to follow symbolic links, false
by default.
the function that defines FileVisitor.