当前位置:主页 > 软件编程 > Python代码 >

Python彻底删除文件夹及其子文件方式

时间: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")

您可能感兴趣的文章:

相关文章