Skip to content

Instantly share code, notes, and snippets.

@davidfoerster
Last active May 19, 2016 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidfoerster/406c5c6dea0fa5098b3a9ab11f9afa10 to your computer and use it in GitHub Desktop.
Save davidfoerster/406c5c6dea0fa5098b3a9ab11f9afa10 to your computer and use it in GitHub Desktop.
#!/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)
@davidfoerster
Copy link
Author

Usage:

python3 rename-videos.py <FILE> ...

Copy link

ghost commented May 19, 2016

Awesome! Thanks for your help. im learning python so i still have a lot to come up to speed on. This helps. Appreciate it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment