Line | |
---|
1 | """Remove computer generated garbage such as |
---|
2 | |
---|
3 | *.py~ |
---|
4 | *.pyc |
---|
5 | *.o |
---|
6 | *.so |
---|
7 | *.dll |
---|
8 | |
---|
9 | Note: Recompile ANUGA after running this script |
---|
10 | """ |
---|
11 | |
---|
12 | import os |
---|
13 | |
---|
14 | |
---|
15 | extensions_to_delete = ['~', |
---|
16 | '.pyc', # Python |
---|
17 | '.o', '.so', '.dll', # C |
---|
18 | '.aux', '.ps', # LaTeX |
---|
19 | '.sww', |
---|
20 | '.stdout'] |
---|
21 | #'.png'] |
---|
22 | |
---|
23 | filenames_to_delete = [] |
---|
24 | for dirpath, dirnames, filenames in os.walk('.'): |
---|
25 | |
---|
26 | print 'Searching dir', dirpath |
---|
27 | |
---|
28 | if '.svn' in dirnames: |
---|
29 | dirnames.remove('.svn') # don't visit SVN directories |
---|
30 | |
---|
31 | |
---|
32 | for filename in filenames: |
---|
33 | for ext in extensions_to_delete: |
---|
34 | if filename.endswith(ext): |
---|
35 | absname = os.path.join(dirpath, filename) |
---|
36 | print ' Flagged for deletion', absname |
---|
37 | filenames_to_delete.append(absname) |
---|
38 | |
---|
39 | |
---|
40 | print |
---|
41 | N = len(filenames_to_delete) |
---|
42 | if N > 0: |
---|
43 | msg = '%d files flagged for deletion. Proceed? (Y/N)[N]' %N |
---|
44 | answer = raw_input(msg) |
---|
45 | |
---|
46 | if answer.lower() == 'y': |
---|
47 | for filename in filenames_to_delete: |
---|
48 | print 'Deleting', filename |
---|
49 | os.remove(filename) |
---|
50 | else: |
---|
51 | print 'Nothing deleted' |
---|
52 | else: |
---|
53 | print 'No files flagged for deletion' |
---|
54 | |
---|
55 | |
---|
56 | |
---|
Note: See
TracBrowser
for help on using the repository browser.