I'm scanning the whole C drive to find jpg files,with this code:
std::string extensions[] = { ".jpg" };
recursive_directory_iterator dir("C:\\"), end;
while (dir != end)
{
if (dir->path() == "C:\\Windows" || dir->path() == "C:\\$Recycle.Bin" || dir->path() == "C:\\Program Files" || dir->path() == "C:\\build_static" || dir->path() == "C:\\Perl" || dir->path() == "C:\\Python" || dir->path() == "C:\\Python27" || dir->path() == "C:\\Qt" || dir->path() == "C:\\Qt-5.9.1" || dir->path() == "C:\\boost_1_65_1") //don't recurse in these directories
{
dir.no_push();// don't recurse into this directory.
}
else
{
auto it = std::find_if(begin(extensions), std::end(extensions),
[&](const std::string& s)
{return dir->path().string().find(s) != std::string::npos; });
if (it != std::end(extensions))
{
cout << dir->path() << endl;
}
}
try
{
++dir;
}
catch (boost::filesystem::filesystem_error& fex)
{
std::cout << fex.what() << std::endl; //display the error
cout << dir->path() << endl; //and where it gets stuck
dir.no_push();
++dir;
}
}
}
The problem is,it's working on almost every folder on the disk,but it throws an access denied error on C:\Users folder,but not on C:\Program Files(x86) (The code runs without admin rights).
So it would recurse into program files (where admin rghts are needed) and not in C:\Users (where admin rights aren't needed) ? Why can't the program access to Users folder and it's subdirectories ?
The code used to work when ran on windows 7 (home) a few months ago.I ran it on windows 10 pro and i get these errors...Would the OS be the cause ? P.S : i'm using boost 1.66 (tried with 1.65 too,same problem)