@ExperimentalPathApi fun fileVisitor( builderAction: FileVisitorBuilder.() -> Unit ): FileVisitor<Path>
Builds a FileVisitor whose implementation is defined in builderAction.
By default, the returned file visitor visits all files and re-throws I/O errors, that is:
To override a function provide its implementation to the corresponding function of the FileVisitorBuilder that was passed as a receiver to builderAction. Note that each function can be overridden only once. Repeated override of a function throws IllegalStateException.
The builder is valid only inside builderAction function. Using it outside the function throws IllegalStateException.
Example:
val cleanVisitor = fileVisitor {
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
}
}
© 2010–2023 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.path/file-visitor.html