www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dirEntries returns relative, not absolute paths

reply number <putimalitze gmx.de> writes:
https://dlang.org/phobos/std_file.html#dirEntries
 The name of each iterated directory entry contains the 
 absolute path.
it seems to be absolute only if the specified path is absolute, or always relative to the parent dir of the specified path. import std.stdio;import std.stdio; void main() { import std.file; import std.path; assert(!"dir".exists); scope(exit) if ("dir".exists) rmdirRecurse("dir"); mkdirRecurse("dir/dir1/dir2/dir3"); writeln("-----"); foreach (DirEntry e; dirEntries("dir", SpanMode.breadth)) { writeln("e: " ~ e); } writeln("-----"); foreach (DirEntry e; dirEntries("../" ~ getcwd.baseName ~ "/dir", SpanMode.breadth)) { writeln("e: " ~ e); } writeln("-----"); foreach (DirEntry e; dirEntries(getcwd ~ "/dir", SpanMode.breadth)) { writeln("e: " ~ e); } // ----- // e: dir/dir1 // e: dir/dir1/dir2 // e: dir/dir1/dir2/dir3 // ----- // e: ../dTests/dir/dir1 // e: ../dTests/dir/dir1/dir2 // e: ../dTests/dir/dir1/dir2/dir3 // ----- // e: /home/user/dTests/dir/dir1 // e: /home/user/dTests/dir/dir1/dir2 // e: /home/user/dTests/dir/dir1/dir2/dir3 }
Feb 06
next sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Tuesday, February 06, 2018 18:58:43 number via Digitalmars-d-learn wrote:
 https://dlang.org/phobos/std_file.html#dirEntries

 The name of each iterated directory entry contains the
 absolute path.
it seems to be absolute only if the specified path is absolute, or always relative to the parent dir of the specified path.
Then the docs need to be fixed. - Jonathan M Davis
Feb 06
prev sibling parent Timothee Cour <thelastmammoth gmail.com> writes:
https://github.com/dlang/phobos/pull/6133

On Tue, Feb 6, 2018 at 1:40 PM, Jonathan M Davis via
Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:
 On Tuesday, February 06, 2018 18:58:43 number via Digitalmars-d-learn wrote:
 https://dlang.org/phobos/std_file.html#dirEntries

 The name of each iterated directory entry contains the
 absolute path.
it seems to be absolute only if the specified path is absolute, or always relative to the parent dir of the specified path.
Then the docs need to be fixed. - Jonathan M Davis
Feb 06