在python中使用shutil模塊刪除指定路徑下的文件夾,具體方法如下:
import os
import shutil #導入shutil模塊
delList = []
delDir = "/home/test"
delList = os.listdir(delDir )
for f in delList:
filePath = os.path.join( delDir, f )
if os.path.isfile(filePath):
os.remove(filePath)
print filePath + " was removed!"
elif os.path.isdir(filePath):
shutil.rmtree(filePath,True)
print "Directory: " + filePath +" was removed!"