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
}

Reply via email to