Skip to content

Instantly share code, notes, and snippets.

@BTruer
Created August 19, 2016 15:38
Show Gist options
  • Save BTruer/37c70d4608b4fb978f3537fda2d5a593 to your computer and use it in GitHub Desktop.
Save BTruer/37c70d4608b4fb978f3537fda2d5a593 to your computer and use it in GitHub Desktop.
This is a script that will rename files if they look a certain way. This is a template so it will need to be customized based on your needs.
import os, sys
allTheFiles = os.listdir(os.getcwd()) #This is a list of all the files in your directory
for filename in allTheFiles: #Each filename is grabed from the list as a string
if("Certain String is in the filename" in filename): #This is an additional check to see if there are only certain files you want to change. Else this check is not needed if you want to change all the files.
os.rename(filename ,"New file name" + filename[33:]) #os.rename(<oldFileName>,<newFileName>); The filename[10:] is if you may want to keep certain parts of the old file name. For help look up python string methods.
print "Rename Complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment