[Python] Removing a non-empty folder
Removing a non-empty folder
You will get an ‘access is denied’ error when you attempt to use
os.remove(“/folder_name”)
to delete a folder which is not empty. The most direct and efficient way to remove non-empty folder is like this:
import shutil
shutil.rmtree(“/folder_name”)
Of course you have other ways that might be less efficient such as use os.walk():
# Delete everything reachable from the directory named in 'top',
# assuming there are no symbolic links.
# CAUTION: This is dangerous! For example, if top == '/', it
# could delete all your disk files.
import os
for root, dirs, files in os.walk(top, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
[Python] Removing a non-empty folder的更多相关文章
- Please select an empty folder to install Android Studio
原因 当前安装的Android Studio的文件夹不是空的 解决 把路径改成一个空文件夹即可
- TensorRT&Sample&Python[fc_plugin_caffe_mnist]
本文是基于TensorRT 5.0.2基础上,关于其内部的fc_plugin_caffe_mnist例子的分析和介绍. 本例子相较于前面例子的不同在于,其还包含cpp代码,且此时依赖项还挺多.该例子展 ...
- Python 【第九章】 Django基础
在windows 命令行上安装Django 在CMD命令行中输入以下命令进行安装. pip install Django 在windows python安装目录上会出现 一个django-admin. ...
- Python on VS Code
install python extension Press F1, and input "ext install python". Then the icon at the le ...
- windows下python web开发环境的搭建
windows下python web开发环境: python2.7,django1.5.1,eclipse4.3.2,pydev3.4.1 一. python环境安装 https://www.pyth ...
- python tar.gz格式压缩、解压
一.压缩 需求描述 现在有一个目录,需要将此目录打包成tar.gz文件.因为有一个Django项目,需要用到此功能! tar.gz 目录结构如下: ./ ├── folder │ ├── .doc ...
- 用Python实现的数据结构与算法:链表
一.概述 链表(linked list)是一组数据项的集合,其中每个数据项都是一个节点的一部分,每个节点还包含指向下一个节点的链接(参考 <算法:C语言实现>). 根据结构的不同,链表可以 ...
- python 中的queue, deque
python3 deque(双向队列) 创建双向队列 import collections d = collections.deque() append(往右边添加一个元素) import colle ...
- Python(正则 re模块)
1. 匹配一个字符 表达式 说明 等价表达式 \d 数字 [0-9] \w 字母.数字.下划线 [a-zA-Z0-9_] . 除换行外任意字符 \s 空格 [\t\n\r\f\v] \D 除数字 ...
随机推荐
- 不谈业务运维的IT主管早晚被淘汰 这里是10条干货
大数网 吴玉征 先说个真实的故事. 前一段时间,有一家知名的国际连锁咖啡公司的自助交易系统(支付宝.微信.ApplePAY)特别慢,工作人员也不知道为什么.由于他们刚上了业务运维,支持这套系统的云智慧 ...
- scala学习之: Flatten a nested list structure
题目要求: (**) Flatten a nested list structure. Example: scala> flatten(List(List(1, 1), 2, List(3, L ...
- 修改Shp文件名称
IWorkspaceFactory factory = new ShapefileWorkspaceFactoryClass(); IWorkspace pworkspace = factory.Op ...
- UNICODE
// "; var i,j; var prevPage = -1; var nextPage = -1; beginId = setList[index].begin / 16 * 16 + ...
- js常用
window.navigator.userAgent.toLowerCase().indexOf("msie") != -1 是否是IE浏览器
- hdu 1387(Team Queue) STL
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- form表单提交路径action="" 时的一种特殊情况
一.说明: 当页面的form表达的action=""时,表示表单会提交到当前页面,但是如果当前页面的URL里已经带有一个参数了,每次提交表达时这个参数依然存在,不管form表单里有 ...
- 一个div,包含两个div,调整文字位置和div平均分布
网页中经常会用到,一个div下平均分布两个小的div,两个小的div,显示的内容为图片还比较好处理,显示文字则不好控制效果,今天写了一个如图效果的 html: <div class=" ...
- 网络-->监控-->交换机端口流量监控
一.取交换机端口流量OID 针对交换机接口速率在100M及以下: in方向:1.3.6.1.2.1.2.2.1.10 out方向:1.3.6.1.2.1.2.2.1.16 针对交换机端口速率在百兆以上 ...
- 九月二十八JS验证
js表单验证 js可用发来在数据被送往服务器前对HTML表单中的这些输入数据进行验证 被js验证的这些典型的表单数据有: >用户是否已填写表单中的必填项目: >用户输入的邮件地址是否是合法 ...