www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [std.file] dirEntries

reply Tobias Pankrath <tobias pankrath.net> writes:
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
next sibling parent Adam <adam anizi.com> writes:
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
prev sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
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