0
我試圖刪除驅動器上的文件夾集合。這些目錄不是空的。我想出了一個解決方案如下:刪除驅動器上的文件夾
import shutil
import os
path = "main/"
folderList = ['Blah', 'Blah', 'Blah'];
print ("Cleaning Project at %s" % path)
for c in folderList:
strippedPath = (path + c).strip("\n")
print ("Cleaning path " + strippedPath)
if os.path.exists(strippedPath):
try:
shutil.rmtree(strippedPath)
except OSError as why:
pass
print ("Done Cleaning Project")
的問題是,如果沒有的try/catch我得到那個說
PermissionError: [WinError 5] Access is denied: 'PathToFileHere'
按Windows上的刪除鍵將正常工作,一個錯誤。有人可以給我一個命令,將刪除這個目錄沒有錯誤?
我m在這裏顯然很明顯,但是這是因爲Python沒有來自操作系統的許可來完成該操作。這不是你可以在代碼中修復的東西;儘管可能有一些類似'subprocess'的解決方法。 – 2014-10-29 17:54:27
是什麼讓這個特殊的文件夾如此特別?它消除了其餘的? – marsh 2014-10-29 17:55:28
[Python:shutil.rmtree在Windows上失敗並且'Access is denied']可能重複](http://stackoverflow.com/questions/2656322/python-shutil-rmtree-fails-on-windows-with-access-is -denied) – Alderven 2014-10-29 18:29:37