Bug 15146 – std.file.dirEntries("") only works on Windows
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
Other
Creation time
2015-10-03T17:09:00Z
Last change time
2016-01-03T14:14:41Z
Keywords
pull
Assigned to
nobody
Creator
dlang-bugzilla
Comments
Comment #0 by dlang-bugzilla — 2015-10-03T17:09:06Z
///////////////////// test.d /////////////////////
import std.algorithm.iteration;
import std.file;
import std.stdio;
void main()
{
dirEntries("", SpanMode.shallow).each!writeln;
}
//////////////////////////////////////////////////
This program runs fine on Windows, but throws on POSIX.
This is because POSIX opendir is defined to return ENOENT if the argument is an empty string:
> [ENOENT] A component of dirname does not name an existing directory or dirname is an empty string.
Although the call to dirEntries can be changed to dirEntries("."), this has the unpleasant effect of prepending "./" to all paths returned by dirEntries. It is additionally a portability hazard (code that works on one OS but not another).
I thus propose to make dirEntries("") call opendir(".") under the hood.
Comment #1 by dlang-bugzilla — 2015-10-03T17:13:20Z