您的位置:首页 > 编程语言 > Python开发

python 按指定规则批量删除多级目录中的文件

2013-10-27 17:11 761 查看
百度云下载文件自动改名的,根本没有覆盖或跳过的选项

系统 win8,用文件查找功能找 *(1).jpg,找出来的文件有不符合这个规则的,我也不知道为什么

找 unixutils 一时没找到好用的

用 totalcmd 也没实现(不过,忘记了 everything 这个利器,时时刻刻在用的...发现 everything 的一个问题,输入正则表达式时会假死)

只好用 python 写一段

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
import re

# search files in path and subpath and del them
top='d:\\baiduyundownload'
print 'deleting'
c = 0
for root, dirs, files in os.walk(top, topdown=False):
#print root, dirs, files
for name in files:
if re.match('.*\(.\)\.(jpg)|(avi)|(mp4)|(wav)|(3gp)|(rar)', name, re.IGNORECASE):
#root changes dynamically
fullname = root + '\\' + name
print fullname
#os.remove(fullname)
c = c+1
print '%d files deleted' % c
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python win8