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

yipeiwu_com5年前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")

以上这篇Python彻底删除文件夹及其子文件方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python-tornado的接口用swagger进行包装的实例

python-tornado的接口用swagger进行包装的实例

写这个文章的主要原因,就是因为没有相关的东西,导致我完全不知道应该怎么做,经过了两个晚上的摸索,终于搞清楚了,如果有谁需要tornado+swagger的输出模式,可以照这个套; 主要是...

Python安装模块的常见问题及解决方法

1、error: command ‘x86_64-linux-gnu-gcc' failed with exit status 解决办法: # Python 3 $ sudo apt...

python实现unicode转中文及转换默认编码的方法

本文实例讲述了python实现unicode转中文及转换默认编码的方法。分享给大家供大家参考,具体如下: 一、在爬虫抓取网页信息时常需要将类似"\u4eba\u751f\u82e6\u7...

Python实现基于C/S架构的聊天室功能详解

Python实现基于C/S架构的聊天室功能详解

本文实例讲述了Python实现基于C/S架构的聊天室功能。分享给大家供大家参考,具体如下: 一、课程介绍 1.简介 本次项目课是实现简单聊天室程序的服务器端和客户端。 2.知识点 服务器...

Python3多进程 multiprocessing 模块实例详解

本文实例讲述了Python3多进程 multiprocessing 模块。分享给大家供大家参考,具体如下: 多进程 Multiprocessing 模块 multiprocessing...