www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15146] New: std.file.dirEntries("") only works on Windows


          Issue ID: 15146
           Summary: std.file.dirEntries("") only works on Windows
           Product: D
           Version: D2
          Hardware: All
                OS: Other
            Status: NEW
          Severity: enhancement
          Priority: P4
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: thecybershadow gmail.com

///////////////////// 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. --
Oct 03 2015