path matching problem
jerro
a at a.com
Tue Nov 27 13:34:51 PST 2012
On Tuesday, 27 November 2012 at 19:40:56 UTC, Charles Hixson
wrote:
> Is there a better way to do this? (I want to find files that
> match any of some extensions and don't match any of several
> other strings, or are not in some directories.):
>
> import std.file;
>
> ...
>
> string exts = "*.{txt,utf8,utf-8,TXT,UTF8,UTF-8}";
> string[] exclude = ["/template/", "biblio.txt",
> "categories.txt",
> "subjects.txt", "/toCDROM/"]
>
> int limit = 1
> // Iterate a directory in depth
> foreach (string name; dirEntries(sDir, exts,
> SpanMode.depth))
> { bool excl = false;
> foreach (string part; exclude)
> { if (part in name)
> { excl = true;
> break;
> }
> }
> if (excl) break;
> etc.
You could replace the inner loop with somehting like:
bool excl = exclude.any!(part => name.canFind(part));
There may be even some easier way to do it, take a look at
std.algorithm.
More information about the Digitalmars-d-learn
mailing list