On Friday, 30 November 2012 at 01:13:13 UTC, Jonathan M Davis
wrote:
On Friday, November 30, 2012 01:24:07 Dan wrote:
Is there a way to walk files with std.file.dirEntries such that
certain directories are skipped (i.e. how to avoid .git
entirely/recursively)?
You can use std.algorithm.filter on its result. Then when it
would iterate to
something which doesn't match filter's predicate, it skips it.
- Jonathan M Davis
That will do the filtering correctly - but what I was hoping was
to actually prune at the directory level and not drill down to
the files in of an unwanted directory (e.g. .git). The problem
with this and what I'm trying to overcome is accessing lots of
files and directories recursively all of which I want to skip.
Much like there is a *followSymlink* it would be nice if a
predicate were accepted to *followDirectory* in general or some
way to cause that.
---------------
static bool desired(string m) {
bool unwanted = match(m, _uninterestRe)? true : false;
writeln("Is unwanted ", m, " ", unwanted);
return !unwanted;
}
static Regex!(char) _uninterestRe = regex(`\.git\b`);
filter!(desired)(dirEntries(root, SpanMode.depth))) {
...
}