https://kotlinlang.org logo
Title
m

mcpiroman

02/23/2022, 5:30 PM
I see this question got not answers 😞 Is it now possible after 1.5 year?
j

Joffrey

02/23/2022, 5:31 PM
There are nice extensions on
File
and
Path
now which may help with that
For instance, there is
path.listDirectoryEntries(glob)
if you don't need to go recursive
m

mcpiroman

02/23/2022, 5:34 PM
Yeees, but it's about recursive glob, and for that I have not found anything
j

Joffrey

02/23/2022, 5:35 PM
Then I think you might need to use
FileTreeWalk
m

mcpiroman

02/23/2022, 5:39 PM
I'd like to just write
glob("a/*/b/*.c")
though 😞
j

Joffrey

02/23/2022, 5:40 PM
You can write an extension using the snippet mentioned in the question you linked if you want to use it this way. I don't think there is more in the stdlib right now, but I don't have extensive knowledge of this area tbh
m

mcpiroman

02/23/2022, 5:45 PM
I can, except as mentioned in OP it is very inefficient for big file trees. I'm fine it to be outside of stdlib, but I can't find any library either.
j

Joffrey

02/23/2022, 5:54 PM
If you believe it's faster, you could also call a separate process to do an actual glob, but then you're platform dependent
Did you actually measure that the performance of this snippet doesn't suit your needs? Given that it gives a sequence of files, you could process them in parallel of the walk
m

mcpiroman

02/23/2022, 6:03 PM
The point is this snippet walks through every file under the given root and then compares the whole path, while the proper glob implementation would skip irrelevant subpaths based on the given pattern.
e

ephemient

02/23/2022, 7:11 PM
I think it's a bit beyond the scope of a kotlin-stdlib that doesn't even have cross-platform IO to begin with, unfortunately