iterate over a directory, dealing with permission errors
Meta via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 18 06:53:43 PDT 2015
On Friday, 18 September 2015 at 12:42:26 UTC, John Colvin wrote:
>> well, creating a DirEntry is not a range operation. handle
>> can't help you there.
>
> Yup :(
I think you could use std.exception.ifThrown in this case.
foreach(file; dirEntries(args[1], SpanMode.depth)
.ifThrown(DirEntry.init)
.handle!(Exception, RangePrimitive.popFront,
(e, r) => DirEntry()))
{
writeln(file.name);
}
Although I'm not exactly sure what to return for the "error"
value... I'm not sure if DirEntry.init will work or not; you'll
probably have to mess around with it.
More information about the Digitalmars-d
mailing list