in Python glob ignores “Permission denied” errors. Unfortunately I need to know if there was a directory which I can’t read.
I could use os.walk() and fnmatch, but maybe there is a better solution?
Example:
user@pc:~
===> python
>>> import glob
>>> glob.glob('/root/*')
[]
There are files in /root, but user@pc is not allowed to read this directory.
A single Exception would not be enough. For example glob.glob('/var/log/*/*.log'). I want to know which directories exist, but are unreadable.
One way to get all the directories and files that cannot be read is indeed use
os.walkto traverse recursively a directory tree and then, for every directory and file, check permissions usingos.access:Note: You could write your own recursive function that traverses the directory structure, but you’ll be basically duplicating
os.walkfunctionality, so I don’t see the use case forglob.glob.