www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dirEntries: How get "." and ".."?

reply kdevel <kdevel vogtner.de> writes:
Why does dirEntries in std/file.d do that (POSIX version)?:

             for (dirent* fdata; (fdata = readdir(_stack[$-1].h)) 
!= null; )
             {
                 // Skip "." and ".."
                 if (core.stdc.string.strcmp(&fdata.d_name[0], 
".") &&
                     core.stdc.string.strcmp(&fdata.d_name[0], 
".."))
                 {
                     _cur = DirEntry(_stack[$-1].dirpath, fdata);
                     return true;
                 }
             }

There seems to be no switch to disable the skip of "."  and "..".
So the original position of these dir entries is lost. ☹
Jan 09 2021
parent reply Anonymouse <zorael gmail.com> writes:
On Saturday, 9 January 2021 at 18:44:10 UTC, kdevel wrote:
 There seems to be no switch to disable the skip of "."  and 
 "..".
 So the original position of these dir entries is lost. ☹
I imagine dirEntries returning an entry for ".." would make for a lot of confusion. Don't you already know "." as the path you passed to dirEntries? What exactly are you trying to do?
Jan 10 2021
parent reply kdevel <kdevel vogtner.de> writes:
On Sunday, 10 January 2021 at 20:39:56 UTC, Anonymouse wrote:
 On Saturday, 9 January 2021 at 18:44:10 UTC, kdevel wrote:
 There seems to be no switch to disable the skip of "."  and 
 "..".
 So the original position of these dir entries is lost. ☹
I imagine dirEntries returning an entry for ".." would make for a lot of confusion.
IMHO the application programmer/software engineer needs no such protection. [sarcasm deleted]
 Don't you already know "." as the path you passed to dirEntries?
I don't know the change date, the uid/gid etc.
 What exactly are you trying to do?
I am refactoring a Filebrowser.
Jan 10 2021
parent oddp <oddp posteo.de> writes:
On 10.01.21 23:15, kdevel via Digitalmars-d-learn wrote:
 Don't you already know "." as the path you passed to dirEntries?
I don't know the change date, the uid/gid etc.
Not as sexy, but can't you manually construct DirEntries [1] by supplying the paths via std.path [2]? DirName [3] should give you the current/parent directory, for example. [1] https://dlang.org/library/std/file/dir_entry.html [2] https://dlang.org/phobos/std_path.html [3] https://dlang.org/phobos/std_path.html#.dirName
Jan 10 2021