Created
September 13, 2014 23:11
-
-
Save dilijev/bf3e69bbb0c2f19aaad0 to your computer and use it in GitHub Desktop.
Python Batch File Renamer
This file contains hidden or 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
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.rename( | |
pathname, | |
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