Thread overview
[Help]How to handle exception from dirEntries?
Jun 17, 2014
Keqin
Jun 17, 2014
Ali Çehreli
Jun 17, 2014
Keqin
June 17, 2014
Hi everyone,

I have write a short program to check file size recursively as bellow.

If i run this exe on windows eg.:
> hello.exe --dir C:\

It will throw as:

std.file.FileException@std\file.d(2519): C:\$Recycle.Bin\S-1-5-18: Access is den
ied.

I believe the exception comes from the following line:
auto entries = dirEntries(dirpath, SpanMode.depth);

I have read the std.file, still have no idea how to get around of it.
Can someone help?

..code-block: d

import std.stdio;
import std.file;
import std.getopt;
string dirpath=".";

void main(string[] args) {
    getopt(args, "dir", &dirpath);
    writeln(dirpath);
    auto entries = dirEntries(dirpath, SpanMode.depth);
    writeln("start while");
    while(!entries.empty)
    {
        try{
            auto entry = entries.front;
            if(entry.isFile())
            {
                writeln(getSize(entry));
            }
            entries.popFront();
        }
        catch(FileException o){
            //handle FileException
        }
        catch(Exception o){
            //handle all other types of exceptions
        }
        finally{
            //do nothing
        }
    }
}
June 17, 2014
On 06/16/2014 09:44 PM, Keqin wrote:> Hi everyone,

> std.file.FileException@std\file.d(2519): C:\$Recycle.Bin\S-1-5-18:
> Access is den
> ied.
>
> I believe the exception comes from the following line:
> auto entries = dirEntries(dirpath, SpanMode.depth);

Known issue:

  https://issues.dlang.org/show_bug.cgi?id=12391

Also see:

  https://issues.dlang.org/show_bug.cgi?id=8967

  https://issues.dlang.org/show_bug.cgi?id=6138

Ali

June 17, 2014
Thanks for your reply!

On Tuesday, 17 June 2014 at 04:50:43 UTC, Ali Çehreli wrote:
> On 06/16/2014 09:44 PM, Keqin wrote:> Hi everyone,
>
> > std.file.FileException@std\file.d(2519):
> C:\$Recycle.Bin\S-1-5-18:
> > Access is den
> > ied.
> >
> > I believe the exception comes from the following line:
> > auto entries = dirEntries(dirpath, SpanMode.depth);
>
> Known issue:
>
>   https://issues.dlang.org/show_bug.cgi?id=12391
>
> Also see:
>
>   https://issues.dlang.org/show_bug.cgi?id=8967
>
>   https://issues.dlang.org/show_bug.cgi?id=6138
>
> Ali