最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python递归删除指定目录及其所有内容的方法
时间:2017-01-16 编辑:简简单单 来源:一聚教程网
实例如下
代码如下 | 复制代码 |
#! /usr/bin/python # -*- coding: utf-8 -*- importos defdel_dir_tree(path): ''' 递归删除目录及其子目录, 子文件''' ifos.path.isfile(path): try: os.remove(path) exceptException, e: #pass printe elifos.path.isdir(path): foriteminos.listdir(path): itempath=os.path.join(path, item) del_dir_tree(itempath) try: os.rmdir(path)# 删除空目录 exceptException, e: #pass printe if__name__=='__main__': dirname='/home/xx/log' del_dir_tree(dirname) |
相关文章
- Pages目录怎么删除 Pages删除目录教程 03-10
- shell 批量删除指定目录下的目录 10-19
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31