Last active
May 19, 2016 02:02
-
-
Save davidfoerster/406c5c6dea0fa5098b3a9ab11f9afa10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys, os, os.path | |
for original_name in sys.argv[1:]: | |
original_name_noext, extension = os.path.splitext(original_name) | |
new_name = original_name_noext[:-11] + extension | |
print('{0!r} => {1!r}'.format(original_name, new_name)) | |
if os.path.exists(new_name): | |
reply = None | |
while reply is None or len(reply) > 1 or reply not in 'YN': | |
reply = input( | |
'»{0}« exists already. Do you want to overwrite it? [y/N] ' | |
.format(new_name) | |
).upper() | |
if reply in 'N': | |
print('Skipped!') | |
continue | |
try: | |
os.rename(original_name, new_name) | |
except OSError as ex: | |
print(ex, file=sys.stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome! Thanks for your help. im learning python so i still have a lot to come up to speed on. This helps. Appreciate it