iterate over a directory, dealing with permission errors

Robert burner Schadek via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 18 05:27:35 PDT 2015


On Friday, 18 September 2015 at 12:17:25 UTC, John Colvin wrote:
> That's neat, didn't know about std.exception.handle

It is at least a year old. I created it because I had a range 
that threw, and there was nothing to keep a range going or 
reenter it.

>
> Unfortunately, I think there are two problems with your 
> solution:
>
> 1) DirIteratorImpl will throw on popFront, not front. I had to 
> look at source to find out. Is this a failure of documentation 
> or is it actually an implementation detail?

That one is trivial RangePrimitive.popFront

foreach(file; dirEntries(args[1], SpanMode.depth)
          .handle!(Exception, RangePrimitive.popFront, (e, r) =>  
DirEntry())) {
      writeln(file.name);
  }

>
> 2) it doesn't cover the case where args[1] itself is 
> unreadable, because dirEntries will throw when it's created.

well, creating a DirEntry is not a range operation. handle can't 
help you there.




More information about the Digitalmars-d mailing list