(oldname,path,first)
| 57 | raise SystemExit |
| 58 | |
| 59 | def getNewName(oldname,path,first): |
| 60 | |
| 61 | global prefix,suffix,replace,count,replaceWith,pattern |
| 62 | |
| 63 | if choice == "SPACE to UNDERSCORE": |
| 64 | newname = oldname.replace(' ', '_') |
| 65 | |
| 66 | elif choice == "UNDERSCORE to SPACE": |
| 67 | newname = oldname.replace('_',' ') |
| 68 | |
| 69 | elif choice == "DASH to SPACE": |
| 70 | newname = oldname.replace('-',' ') |
| 71 | |
| 72 | elif choice == "SPACE to DASH": |
| 73 | newname = oldname.replace(' ','-') |
| 74 | |
| 75 | elif choice == "Replace Manually": |
| 76 | newname = oldname.replace(replace,replaceWith) |
| 77 | |
| 78 | elif choice == "ALL CAPITAL": |
| 79 | newname = oldname.upper() |
| 80 | |
| 81 | elif choice == "all lower": |
| 82 | newname = oldname.lower() |
| 83 | |
| 84 | elif choice == "First letter uppercase": |
| 85 | newname = oldname.capitalize() |
| 86 | |
| 87 | elif choice == "First Letter Uppercase In Each Word": |
| 88 | newname = oldname.title() |
| 89 | |
| 90 | elif choice == "Add a Prefix": |
| 91 | newname = prefix + oldname |
| 92 | |
| 93 | elif choice == "Add a Suffix": |
| 94 | #Place suffix before the extension if it got ... |
| 95 | if oldname.find('.') != -1: |
| 96 | newname = oldname.split('.')[0] + suffix + '.' + oldname.split('.')[1] |
| 97 | else: |
| 98 | newname = oldname + suffix |
| 99 | |
| 100 | elif choice == "Patternize": |
| 101 | |
| 102 | newname = pattern |
| 103 | |
| 104 | #for number substiution |
| 105 | c = re.compile(r'(\{num\d*\}|(\{num\d*\+\d*\}))') |
| 106 | if c.search(newname): |
| 107 | tmp = c.search(newname).group() |
| 108 | |
| 109 | #if it is a directory just set count 0 and pass |
| 110 | if os.path.isdir(path) and first == 1: |
| 111 | newname = c.sub("",newname) |
| 112 | count = 1 |
| 113 | #if {num3} |
| 114 | elif len(tmp)== 6: |
| 115 | substitute = str(count).zfill(int(tmp[4])) |
| 116 | newname = c.sub(substitute, newname) |
no test coverage detected