Skip to content

Instantly share code, notes, and snippets.

Created Sep 13, 2014
What would you like to do?
Python Batch File Renamer
import re, glob, os
def renamer(files, pattern, replacement):
for pathname in glob.glob(files):
basename= os.path.basename(pathname)
new_filename= re.sub(pattern, replacement, basename)
if new_filename != basename:
os.path.join(os.path.dirname(pathname), new_filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment