Thread overview
[std.file] dirEntries
Dec 12, 2011
Tobias Pankrath
Dec 12, 2011
Adam
Dec 12, 2011
Vladimir Panteleev
December 12, 2011
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
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
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);