boost::filesystem -> recursive_directory_iterator no EACCESS to folder/files

Hi everybody,

if you use boost and the recursive iterator method to scan your local system
and e.g. one folder like "C:\Documents and Settings", the user does not have
access (EACCESS), boost throws an exception and stop the scan process.

Example method:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <boost\filesystem.hpp> 
namespace fs = boost::filesystem; 

void FileSystem::scanDrive(const string& drive) 
{ 
    try 
    { 
        for(fs::recursive_directory_iterator dir_end, dir(drive); dir != dir_end; ++dir) 
        { 
            fs::path _path(*dir); 
            if(!fs::is_directory(_path)) 
            { 
                cout << _path.file_string() << endl; 
            } 
        } 
    } 
    catch(fs::filesystem_error e) 
    { 
        cout << e.what() << endl; 
    } 
}


Do you know if it's possible to catch this exception properly and does not
stop this process. I mean, if a folder with not access comes, go to the next
one and ignore it.

Many thanks in advance for your help,
Daniel
Move the try/catch into the loop.
Hi kbw,

thanks for replay however this I already tried without better results. You can set one try/catch
outside of the loop and one try/catch inside the loop. This helps only to not display an error
message but does not help to run/scan further :-(

Cheers
Daniel
Last edited on
I can't get it to fail on Windows. I'll check in on OS X later.
Topic archived. No new replies allowed.