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
        }
    }
}

Reply via email to