1

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)

EinderJam
  • 417
  • 1
  • 6
  • 20

1 Answers1

2

The problem is literally as stated: you donot have permission to read/traverse C:\Users.

So it would recurse into program files (where admin rghts are needed)

Who says admin rights are needed?! To write, yes, not to read or traverse.

and not in C:\Users (where admin rights aren't needed) ?

Exactly the inverse (you have write permissions on the parts that you own, like your own profile)

Why can't the program access to Users folder and it's subdirectories ?

Because of the access control instated by the operating system

I suggest reading up on NTFS ACLs: http://www.ntfs.com/ntfs-permissions-acl-use.htm

sehe
  • 374,641
  • 47
  • 450
  • 633
  • So the access control changed between Windows 7 and 10 ? And how can I recurse through my own profile folders if I can't go into C:\Users ? – EinderJam Jan 01 '18 at 17:01
  • Possibly. That makes sense. It might also depend on administrative choices. If the defaults changed that is likely to be documented by Microsoft or by the community online – sehe Jan 01 '18 at 17:08
  • The fact you can't traverse a parent folder doesn't prevent access to a child folder if you address it by name. – sehe Jan 01 '18 at 17:09
  • So i could make a list of subdirectories and try to recurse into each one ? – EinderJam Jan 01 '18 at 17:14
  • Yes. The usual approach is to ask the OS for your profile home (https://stackoverflow.com/questions/198124/how-can-i-get-the-path-of-a-windows-special-folder-for-a-specific-user) – sehe Jan 01 '18 at 17:18