删除指定格式的文件

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
 
"""
2015.07.02
Clean all the genrated files during compile.             Edited by Grey
"""
 
import os,re
 
def CleanAll(file_ext):
    # remove all files in bin
    for root,dirs,files in os.walk('./bin'):
        for each_file in files:
            try:
                os.chdir('./bin')
                os.remove(each_file)
                os.chdir('../')
            except:
                pass
    # remove all object files in source foulder
    for root,dirs,files in os.walk('./'):
        pwd = os.getcwd()
        os.chdir(root)
        object_file_list = [f for f in os.listdir('.') if f.endswith(file_ext)]
        for file in object_file_list:
            os.remove(file)
        os.chdir(pwd)
 
CleanAll('.o')
CleanAll('.rar')
CleanAll('.xls')
CleanAll('.xlsx')
CleanAll('.tmp')
CleanAll('.txt')
CleanAll('.lnk')
CleanAll('.doc')
CleanAll('.docx')
CleanAll('.ppt')
CleanAll('.pptx')
CleanAll('.bak')
CleanAll('.c')
CleanAll('.h')
CleanAll('.pdf')
print "All the files and all the files in 'bin' have been removed!"