On Friday, 18 September 2015 at 14:35:39 UTC, Dmitry Olshansky wrote:
On 18-Sep-2015 15:03, Adrian Matoga wrote:
On Friday, 18 September 2015 at 11:35:45 UTC, John Colvin wrote:
Posting here instead of learn because I think it uncovers a design flaw

void main(string[] args)
{
    import std.file : dirEntries, SpanMode;
    import std.stdio : writeln;
    foreach(file; dirEntries(args[1], SpanMode.depth))
        writeln(file.name);
}

Modify this program such that it will print "<file.name> access denied" instead of crashing with an exception whenever it hits a permissions problem. Remember that you might not even have permission
to read the directory given in args[1]. Remember that access
permissions can change at any time.

It can be done, but it is seriously ugly.

https://github.com/D-Programming-Language/phobos/pull/931

I had to move to some urgent stuff instead of improving the PR and later I forgot about it. The discussion points out what not to do when solving
this issue. :)

FYI

https://github.com/D-Programming-Language/phobos/pull/2768

I came across the same problem a few years ago. I can't remember if a bug was raised. it would be very handy to document the way to get around this in the dirEntries pages, especially if it involves a little convolution.

Reply via email to