Chinaunix首页 | 论坛 | 博客
  • 博客访问: 938
  • 博文数量: 1
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 20
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-18 22:28
文章分类

全部博文(1)

文章存档

2011年(1)

我的朋友
最近访客

分类: Python/Ruby

2011-07-19 14:06:41

# -*- coding: cp936 -*-
#删除当前目录下所有子目录下所有指定扩展名的文件
import sys,os,glob,re

#配置1
array =("pdb","txt")

#程序开始
strRegex ="";
for i in range(len(array)):
    strRegex = strRegex +r".*\."+array[i]+r"$"
    if(i
        strRegex +="|";
pattern = re.compile(strRegex)

for root,dirs,files in os.walk("./"):
    for stringT in files:
      match = pattern.match(stringT)
      if match:      
        pathFile = os.path.join(os.path.abspath(root),stringT);
        print(pathFile)
            
print("!!!!!!!!以上文件将被删除,强制关闭结束!!!!!!!!")
os.system("pause")

for root,dirs,files in os.walk("./"):
    for stringT in files:
      match = pattern.match(stringT)
      if match:
        pathFile = os.path.join(os.path.abspath(root),stringT);
        buildCmd = 'del '+ pathFile
        print(buildCmd)
        if(1==os.system(buildCmd)):
            print(r"del " + buildCmd + r" Failed" + "\n")

os.system("pause")


阅读(351) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~