Scaffold/app/src/FileGlob.kt

22 lines
635 B
Kotlin

package scaffold
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
object FileGlob {
fun listFiles(root: Path, glob: String): MutableList<Path> {
val matcher = FileSystems.getDefault().getPathMatcher("glob:$root/$glob")
val matches = mutableListOf<Path>()
Files.walkFileTree(root, object : SimpleFileVisitor<Path>() {
override fun visitFile(file: Path, attrs: BasicFileAttributes?): FileVisitResult {
if (matcher.matches(file)) matches.add(file)
return FileVisitResult.CONTINUE
}
})
return matches
}
}