summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcomic-rename.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/comic-rename.py b/comic-rename.py
new file mode 100755
index 0000000..15b6046
--- /dev/null
+++ b/comic-rename.py
@@ -0,0 +1,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()
+