Thread overview | |||||
---|---|---|---|---|---|
|
December 12, 2011 [std.file] dirEntries | ||||
---|---|---|---|---|
| ||||
Hello, I'm struggling with std.file.dirEntries. I want iterate over every file below a directory, which name starts with "test_" and does not contain a point ("."). I've tried this, but it does not work: -- foreach(DirEntry de; dirEntries("myDir", "temp_[!.]*", SpanMode.breadth)) { writeln(de.name); } -- It also prints names of files, which names do contain points. I can't see, what I'am doing wrong. Can anyone help? Tobias |
December 12, 2011 Re: [std.file] dirEntries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | I'm not sure if it's a different RegEx pattern than other languages, but you may wish to try: temp_[^\.]* [] typically indicates a character class or set of characters. ^ is used to indicate unallowed / exception characters . will typically need to be escaped, depending on context. |
December 12, 2011 Re: [std.file] dirEntries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | On Monday, 12 December 2011 at 14:43:38 UTC, Tobias Pankrath wrote: > I can't see, what I'am doing wrong. Can anyone help? You can't do this only using a glob. The glob syntax used by dirEntries is described here: http://dlang.org/phobos/std_path.html#globMatch You can do this with std.algorithm.filter: auto files = filter! q{a.name.startsWith("temp_") && !a.name.canFind('.')} (dirEntries("myDir", SpanMode.breadth)); foreach (de; files) writeln(de.name); |
Copyright © 1999-2021 by the D Language Foundation