dirEntries throws exception on broken symlinks

dennis dennisr at visi.com
Sun Jan 5 13:17:07 PST 2014


I a using dirEntries to list recursively build a list of all 
files in all subdirectories but dirEntries is throwing an 
exception when it encounters a broken link.

I want just report the exception, then ignore the broken link and 
then continue processing the rest of the dir's and files.

Do I need to create my own implementation of a dirEntries 
function to solve this?

Also in the example code below I am getting a segfault when I try 
to extract the errno from the exception object and I am not sure 
why the segfault is happening, is it my code or a bug?

Example Code:

import std.stdio;
import std.file;


void main(string[] args)
{

     try {
         foreach (string name; dirEntries(args[1], 
SpanMode.breadth))
         {
             writefln(name);
         }
     }
     catch(Exception o) {
         writefln(o.toString());
         writefln("%d",(cast(FileException)o).errno);

     }
}


More information about the Digitalmars-d-learn mailing list