网络编程
位置:首页>> 网络编程>> Python编程>> Python彻底删除文件夹及其子文件方式

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

作者:路至晴空  发布时间:2022-07-27 04:18:53 

标签: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")

来源:https://blog.csdn.net/yanlintao1/article/details/80102286

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com