1

I have this simple python script;

def scanFolder(path="."):
    foldersList = []
    for name in os.listdir(path):
        if os.path.isdir(name):
            for innerName in os.listdir(name):
                if os.path.isdir(innerName):
                    foldersLIst.append(innerName)

when run this script i get this error message:

Traceback (most recent call last):
  File "upNew.py", line 42, in <module>
  File "upNew.py", line 18, in __init__
    scanFolder(path=".")
  File "upNew.py", line 24, in scanFolder
    for innerName in os.listdir(name):
PermissionError: [WinError 5] Access is denied: 'System Volume Information\\*.*'

How can i solve this? I'm on Windows 7, using python 3.3

1
  • Ah, the new exception hierarchy! Much easier to say except PermissionError than except IOError as e: if e.errno != ...: raise. Commented Apr 13, 2013 at 0:14

1 Answer 1

3

Windows contains some directories that are protected, by default, against any normal user (including admins). You cannot examine these directories (with any program) unless you ask Windows for permission to access them.

So, you'll probably just want to skip the directories entirely:

try:
    dirs = os.listdir(name)
except PermissionError:
    print("Permission denied:", name)
    continue
for innerName in dirs:
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.