blob: 15b6046f1104f3f8b3a52ed762dee006ef50a9b7 (
plain)
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
|
#!/usr/bin/python
import os
import re
import string
def cleanup_filename(strname):
(strfile, strext) = os.path.splitext(strname)
strext = string.strip(strext)
if strext == '.cbr' or strext == '.cbz':
pattobj = re.compile("\(+(.*)")
pattobj2 = re.compile("__")
pattobj3 = re.compile("_")
name = re.sub(pattobj, "", strfile)
name = re.sub(pattobj2, " ", name)
name = re.sub(pattobj3, " ", name)
return name.rstrip() + strext
else:
return ''
def rename_file(currdir,f):
c = cleanup_filename(f)
if (c != "" and c != f):
print "%s -> %s\n" % (f,c)
os.rename (currdir + os.sep + f, currdir + os.sep + c)
return
def process_dir(currdir):
for f in os.listdir(currdir):
if not os.path.isdir(f):
rename_file(currdir, f)
return
def main():
process_dir('.')
return
if __name__=='__main__':
main()
|