在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!"