I'm trying to write a recursive file listing program in Python. When I run the program without the exception catching code at the end, it returns error number 5, saying that access is denied to some windows folders. I have admin privileges and everything, but it still keeps throwing me this error. Is it at all possible to get around this and list the files in those directories?
import os
def wrapperList():
mainList = []
fileList = os.listdir("C:")
for file in fileList:
path = os.path.join("C:\\", file)
if (os.path.isdir(path)):
mainList.append(recurList(path))
else:
mainList.append(path)
print mainList
def recurList(directory):
try:
fileList = os.listdir(directory)
tempList = []
for file in fileList:
path = os.path.join(directory, file)
if (os.path.isdir(file)):
tempList.append(recurList(path))
else:
tempList.append(file)
return tempList
except:
return ["Access Denied"]
wrapperList()