python删除非空目录的方法
2015-06-19 16:16
609 查看
#!/usr/bin/env python #-*- coding: utf-8 -*- import win32con, win32api,shutil,os def removePath(destinationPath): ''' @summary: 删掉destinationPath目录,当然包括其中的子目录和文件 @param destinationPath: 所给目标目录 ''' if os.path.exists(destinationPath): pathList = os.listdir(destinationPath) for path in pathList: pathFull = os.path.join(destinationPath,path) if os.path.isfile(pathFull): win32api.SetFileAttributes(pathFull, win32con.FILE_ATTRIBUTE_NORMAL) if os.path.isdir(pathFull): removePath(pathFull) shutil.rmtree(destinationPath,True) if __name__ == '__main__': path = r'e:\test\test' removePath(path)
相关文章推荐
- (转)如何使用Psyco为你的Python程序提速。
- Python模块subprocess小记
- windows平台下如何用Python杀进程
- python round(x)函数
- 用Python生成不依赖dll的exe的操作步骤简介
- python的xml库操作读写文件真是慢的无语,跟直接操作文本型的操作真不是一个级别的
- 使用Python和xml.etree.ElementTree解析xml文件
- python 调用word打开doc文档报错,“word无法启动转换器mswrd632.wpc”
- eclipse新建python项Project interpreter not specified
- python Word 编程
- python数组交集、并集与不同
- python数组交集、并集与不同
- python链接mysql常见问题汇总
- 【转】Python2.6下安装Mysqldb出现DeprecationWarning: the sets module is deprecated from sets错误解决方案
- python解码\'\\u\'字符串
- 用reindent.py修复python代码缩进(tab键引发的问题)
- python调用的动态连接库的方法(ctypes)
- Python urllib2 设置超时时间
- Python urllib2 设置超时时间
- 利用Python内置函数getattr轻松实现分发模式