Reputation: 294
I need to find a file in a directory using Kotlin. Something like:
ls *.bld
If there are a couple results, that's ok. It would be a short list. Now there's thousands of files.
Upvotes: 3
Views: 4638
Reputation: 8106
You could create a File object for a directory and then filter on the walk.
val path = File("/path/to/files/directory")
path.walk().filter { it.name.endsWith(".bld") }
PS: walk() returns a Sequence of contents of directory
Upvotes: 8