-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.py
63 lines (55 loc) · 1.28 KB
/
cleanup.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import glob
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'--root',
help='Root directory of your LaTeX project',
type=str)
args = parser.parse_args()
if args.root and not os.path.isdir(args.root):
sys.exit("Error: directory '{0}' not found".format(args.root))
file_patterns = [
'*.aux',
'*.bbl',
'*.blg',
'*.lof',
'*.log',
'*.lol',
'*.lot',
'*.out',
'*.toc',
'*.glo',
'*.idx',
'*.ist',
'*.acn',
'*.acr',
'*.alg',
'*.dvi',
'*.glg',
'*.gls',
'*.ilg',
'*.ind',
'*.maf',
'*.mtc',
'*.mtc1',
'*.synctex.gz'] # file patterns to remove
counter = 0 # counts removed files
def remove(filepath):
global counter
try:
os.remove(filepath)
counter += 1
except OSError:
print "Failed to remove file '{0}'".format(filepath)
if not args.root:
for pattern in file_patterns:
for filepath in glob.glob(pattern):
remove(filepath)
else:
for dirpath, dirnames, filenames in os.walk(args.root):
for pattern in file_patterns:
for filepath in glob.glob(os.path.join(dirpath, pattern)):
remove(filepath)
print u'\U0001F37B' + " Cheers! {0} file(s) removed.".format(counter)