在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!"
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: python多线程数据共享怎么实现