I'd like to walk a tree and end up with a list with a maximum of one file from each directory. The only criteria for the selected files are that they match a glob/pattern, for example "*.txt
".
In case it's not already implicit I need the algorithm to return stable results.
e.g. Given a tree that looks like this:
a/some/entry/foo.html
a/some/entry/foo.txt
a/some/entry/bar.txt
a/some/entry/baz.txt
a/some/entry/baz.bmp
a/some/boo.bat
a/some/boo.txt
a/some/bat.txt
a/other/path/far.txt
a/other/path/faz.txt
One acceptable result would be:
"a/some/entry/bar.txt a/other/path/far.txt a/some/boo.txt"
It seems like GLOB_RECURSE
and find_file
aren't appropriate for this task, so is there another approach that I should consider?