Skip to content

Instantly share code, notes, and snippets.

@mattjared
Last active March 29, 2016 18:59
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 mattjared/3696538b0995e3fee04e480035b89708 to your computer and use it in GitHub Desktop.
Save mattjared/3696538b0995e3fee04e480035b89708 to your computer and use it in GitHub Desktop.
Rename Files in Python
import glob, os
def rename(dir, pattern, titlePattern):
for pathAndFileName in glob.iglob(pattern):
print pathAndFileName
os.rename(pathAndFileName, titlePattern % pathAndFileName)
rename(r'~/Path/to/directory', r'*.file-type', r'newName-%s')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment