L
L
lerny2021-09-03 15:07:47
File systems
lerny, 2021-09-03 15:07:47

How to exclude folders to which the user does not have access Python os?

There is a function that iterates over directories and in the process stumbles upon such as C:\$Recycle.Bin\ . os.access() outputs True for each flag, but if you pass this path to os.listdir() it gives an error (PermissionError: [WinError 5] Permission denied) How to exclude such directories in Python?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ScriptKiddo, 2021-09-03
@ScriptKiddo

try: 
    ...
except PermissionError as e:
    print(e)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question