Skip to content

Instantly share code, notes, and snippets.

@motleytech
Created May 22, 2016 05:48
Show Gist options
  • Save motleytech/1557394c6061e6e464469b54fbae2749 to your computer and use it in GitHub Desktop.
Save motleytech/1557394c6061e6e464469b54fbae2749 to your computer and use it in GitHub Desktop.
rename files python drag drop target
import os
import sys
from pprint import pprint as pp
inpFiles = sys.argv[1:]
replacements = [
('.', ' '),
]
def doRenaming(fake=True):
for fpath in inpFiles:
dpath, fname = os.path.split(fpath)
parts = fname.split('.')
fname, ext = '.'.join(parts[:-1]), parts[-1]
for ft, rt in replacements:
fname = fname.replace(ft, rt)
fname = fname + '.' + ext
newpath = os.path.join(dpath, fname)
if fake:
print newpath
else:
os.rename(fpath, newpath)
doRenaming(fake=True)
res = raw_input('continue with renaming? ')
if res in ('y', 'Y'):
print 'OK... renaming.'
doRenaming(fake=False)
raw_input('Done... press enter to exit.')
else:
raw_input('Aborting renaming... press enter to exit.')
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment