dirEntries removes entire branches of empty directories

Ali Çehreli acehreli at yahoo.com
Wed Nov 9 19:05:58 UTC 2022


In case it matters, the file system is ext4.

1) Create a directory:

   mkdir deleteme

and then run the following program:

import std;

void main() {
     foreach (e; dirEntries(absolutePath("./deleteme"), SpanMode.breadth)) {
         writeln(e.name);
     }
}

Understandably, the top level directory 'deleteme' will not be printed.

2) Make a sub-directory:

   mkdir deleteme/a

Running the program shows no output; 'a' is not visited as a directory 
entry.

3) Create a file inside the sub-directory:

   touch deleteme/a/x

Now the program will show 2 entries; the branch is accessible:

/home/ali/d/./deleteme/a
/home/ali/d/./deleteme/a/x

Imagine a program that wants to make sure the directory structure is 
intact, even the empty directories should exist. Can you think of a 
workaround to achieve that?

Do you think this is buggy behavior for dirEntries?

Ali


More information about the Digitalmars-d-learn mailing list