[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 除数字 ...
随机推荐
- 初学c# -- 学习笔记(一)
初学c# -- 学习笔记(一) 学习C#了,参考许多资料,一步步学习.这一段学习ajax的工作原理,参照其他例子写了web版的群聊小程序,全部文件代码也就不到300行,很简单.使用时先输入用户名,点确 ...
- apache目录浏览
DocumentRoot "/Library/WebServer/Documents" <Directory "/Library/WebServer/Documen ...
- xcode7、iOS9 设置启动图片(Launch Image)
主要是解决上架的时候遇到的问题,顺便把LaunchImage的使用学习一下,一开始项目使用的xib作为启动页的,最近上架打包的时候报错,通不过,问题如下: ERROR ITMS-90096: &quo ...
- TCP、UDP、IP 协议分析(转)
http://blog.chinaunix.net/uid-26833883-id-3627644.html
- [转]VS2013自带SQL Server 的启用方法
本文转自:http://www.icharm.me/vs2013%E8%87%AA%E5%B8%A6%E7%9A%84%E6%95%B0%E6%8D%AE%E5%BA%93sql-server-exp ...
- jQuery与Ajax的应用——《锋利的jQuery》(第2版)读书笔记3
第6章 jQuery与Ajax的应用 jQuery对Ajax操作进行了封装,在jQuery中$.ajax()方法属于最底层的方法,第2层是load().$.get()和$.post()方法,第3层是$ ...
- golang gbk转utf8 mssql access
package ms2mysql import ( "bytes" "golang.org/x/text/encoding/simplifiedchinese" ...
- jQuery Mobile 表单基础
jQuery Mobile 会自动为 HTML 表单添加优异的便于触控的外观. jQuery Mobile 表单结构 jQuery Mobile 使用 CSS 来设置 HTML 表单元素的样式,以使其 ...
- C#设置字体(FontDIalog)、颜色(ColorDialog)对话框控件
设置字体控件为FontDialog,设置颜色的控件为ColorDialog.这两个控件的使用和OpenFileDialog(打开文件)及FolderBroswerDialog(打开文件夹)的使用类似. ...
- spring缓存
Spring Cache使用详解 复制过来时的地址:http://blog.csdn.net/xiaoyu411502/article/details/48901555 标签: spring-bo ...