Python彻底删除文件夹及其子文件方式
作者:路至晴空 时间:2022-07-27 04:18:53
我就废话不多说了,直接上代码吧!
#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
标签:Python,删除,文件夹,子文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python 可变类型和不可变类型及引用过程解析
2021-07-13 00:04:27
标签水平右对齐更适合中文网站
2009-05-01 11:54:00
![](https://img.aspxhome.com/file/UploadPic/20095/1/01-51s.gif)
PHP如何实现HTTP验证
2023-09-04 05:32:46
ASP--IP字段截取
2009-05-26 15:47:00
pycharm设置虚拟环境与更换镜像教程
2023-06-10 06:58:05
![](https://img.aspxhome.com/file/2023/7/78447_0s.jpg)
python实现聊天小程序
2023-11-07 05:17:51
![](https://img.aspxhome.com/file/2023/1/80651_0s.png)
python获取指定网页上所有超链接的方法
2023-07-18 11:50:20
实例介绍Python中整型
2021-03-09 08:00:33
详解python中的线程与线程池
2022-02-02 18:27:19
asp 存储过程分页代码第1/2页
2011-04-03 10:39:00
![](https://img.aspxhome.com/file/UploadPic/20112/5/201125112228776s.jpg)
教你如何使用php session
2023-11-15 06:28:01
python 并发下载器实现方法示例
2022-03-31 10:46:00
python脚本第一行如何写
2021-03-24 22:56:32
Pandas时间序列重采样(resample)方法中closed、label的作用详解
2023-01-31 17:46:36
网站大改版=壮烈的死亡 ?
2009-04-03 14:09:00
![](https://img.aspxhome.com/file/UploadPic/20094/3/200903240046305586-33s.jpg)
浅析python标准库中的glob
2023-08-04 02:39:10
Python3使用xlrd、xlwt处理Excel方法数据
2023-04-03 03:25:29
![](https://img.aspxhome.com/file/2023/6/82766_0s.png)
python 使用socket传输图片视频等文件的实现方式
2022-11-12 11:55:37
Python统计纯文本文件中英文单词出现个数的方法总结【测试可用】
2023-05-14 08:03:02
python3 线性回归验证方法
2022-12-03 10:49:09