그래서 비어 있지 않은 디렉토리를 청소해야합니다. 난 내가 rmtree 및 RMDIR를 사용하려고 JDK가 설치파이썬에서 비어 있지 않은 디렉토리를 삭제하십시오.
def clean_dir(location):
fileList = os.listdir(location)
for fileName in fileList:
fullpath=os.path.join(location, fileName)
if os.path.isfile(fullpath):
os.chmod(fullpath, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
os.remove(location + "/" + fileName)
elif os.path.isdir(fullpath):
if len(os.listdir(fullpath)) > 0:
clean_dir(fullpath)
#os.rmdir(location + "/" + fileName)
shutil.rmtree(location + "/" + fileName)
return
을 제거하려고 다음 function.For 테스트 이유를 만들었습니다,하지만 실패합니다. 내가 rmtree를 사용하여있어
오류 :
OSError: Cannot call rmtree on a symbolic link
을 그리고 이것은 내가 rmdir을 사용할 때 내가 가진 오류입니다 :
OSError: [Errno 66] Directory not empty: '/tmp/jdk1.8.0_25/jre/lib/amd64/server'
코드는 창에 올바르게 작동합니다. 하지만 어떤 이유로 리눅스에서 실패합니다.
에 대한 새로운 ELIF를 추가하고 링크 해제 옵션을 추가했다. https://en.wikipedia.org/wiki/Symbolic_link – iScrE4m
심볼릭 링크라면'os.unlink (...)'만 있으면 충분하다고 생각합니다. (명확히하기 위해 심볼릭 링크를 지울 뿐이며 심볼릭 링크가 가리키는 것은 삭제하지 않습니다.) – smarx
IIRC,'os.unlink'도 파일을 삭제해야합니다. – kronenpj