Basically I have a FileExplorer class written in Python 2.6. It works great, I can navigate through drives, folders, etc.
However, when I get to a specific folder ‘C:\Documents and Settings/.*’*, os.listdir, on which my script is based, throws this error:
WindowsError: [Error 5] Access is denied: ‘C:\Documents and Settings/.‘
Why is that? Is it because this folder is read-only? Or is it something Windows is protecting and my script cannot access?!
Here is the offending code(line 3):
def listChildDirs(self):
list = []
for item in os.listdir(self.path):
if item!=None and\
os.path.isdir(os.path.join(self.path, item)):
print item
list.append(item)
#endif
#endfor
return list
In Vista and later, C:\Documents and Settings is a junction, not a real directory.
You can’t even do a straight
dirin it.Sadly, using
os.path.isdir(), it will returnTrueYou could have a look at these answers for dealing with symlinks in Windows.