파이썬에서 재귀 파일 목록 프로그램을 작성하려고합니다. 끝에 예외 코드를 넣지 않고 프로그램을 실행하면 오류 번호 5, 이 반환되어 일부 Windows 폴더에 대한 액세스가 거부되었음을 알립니다. 관리자 권한과 모든 권한이 있지만 여전히이 오류가 계속 발생합니다. 이 문제를 해결하고 해당 디렉토리에있는 파일을 나열 할 수 있습니까?오류 5 폴더를 재귀 적으로 보려고 할 때
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()
코드에 연결하거나 게시하지 마시고 예외를 게시하십시오. 편집 : 귀하의 게시물에 넣어 코드를 수정했지만 예외를 추가해야합니다. –