digitalmars.D.learn - [std.file] dirEntries
- Tobias Pankrath (14/14) Dec 12 2011 Hello,
- Adam (6/6) Dec 12 2011 I'm not sure if it's a different RegEx pattern than other languages,
- Vladimir Panteleev (10/11) Dec 12 2011 You can't do this only using a glob. The glob syntax used by
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
Dec 12 2011
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.
Dec 12 2011
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);
Dec 12 2011