时间:2021-07-18 08:27:17 | 栏目:Python代码 | 点击:次
我就废话不多说了,直接上代码吧!
#coding:utf-8 import os import stat import shutil
#filePath:文件夹路径
def delete_file(filePath):
if os.path.exists(filePath):
for fileList in os.walk(filePath):
for name in fileList[2]:
os.chmod(os.path.join(fileList[0],name), stat.S_IWRITE)
os.remove(os.path.join(fileList[0],name))
shutil.rmtree(filePath)
return "delete ok"
else:
return "no filepath"
print os.path.exists("E:\\biancheng\\python\\ascas")
print delete_file("E:\\biancheng\\python\\ascas")