prune with dirEntries
Joshua Niehus
jm.niehus at gmail.com
Thu Nov 29 23:29:58 PST 2012
On Friday, 30 November 2012 at 06:29:01 UTC, Joshua Niehus wrote:
> I think if you go breadth first, you can filter out the
> unwanted directories before it delves into them
oh wait... it probably still looks through all those dir's.
What about this?
import std.algorithm, std.regex, std.stdio, std.file;
import std.parallelism;
DirEntry[] prune(string path, ref DirEntry[] files)
{
auto exclude = regex(r"\.git|\.DS_Store", "g");
foreach(_path; taskPool.parallel(dirEntries(path,
SpanMode.shallow)
.filter!(a => match(a.name, exclude).empty)))
{
files ~= _path;
if (isDir(_path.name)) { prune(_path.name, files); }
}
return files;
}
void main()
{
DirEntry[] files;
prune("/path", files);
foreach(file;files) { writeln(file.name); }
}
More information about the Digitalmars-d-learn
mailing list