On Friday, 18 May 2012 at 22:10:36 UTC, Arne wrote:
According to:
http://dlang.org/phobos/std_path.html#globMatch
it is possible to use wildcards spanning multiple directories.
assert (globMatch(`foo/foo\bar`, "f*b*r"));
But wildcards with dirEntries() seem less powerful.
`c:\partial*\path\*.d`
If I were to use:
absolutePath + filter! + globMatch
I would expand too many unrelated directories, no?
I happen to know in my case that 'partial*' will match exactly
one directory, but I don't know the complete name...
So am I left with tokenizing dirSeparator and 'cd' into one
directory at a time? Or am I missing some magic D function
which does everything? (wouldn't be the first time that
happened to me ;) hence my question).
I haven't used globMatch, but I've used nested dirEntries
wildcard expansion loops.
I used SpanMode.shallow parameter with dirEntries to limit
matches to one directory level.
I don't change directories with cd. I just create a list of
matches for the first level partial match, then create an inner
loop that concatenates the matches from the first partial match
and calls dirEntries again.
Here is a link to some code for the wildArgv single level search
that I'm using.
https://github.com/jnorwood/file_utils
This is roughly how I was using it, related to your example
string[] argv;
argv ~= r"c:\partial*";
foreach( dirn; wildArgvs(argv[0..$])){
string[] argv2 = null;
argv2 ~= dirn ~ r"\path\*.d";
foreach( filen; wildArgvs(argv2[0..$])){
do something with filen
}
}