10-30-2012, 07:52 PM
Registered: Oct 2012
Just what I was looking for!
Thanks for posting the awesome script -- it's exactly what I was looking for!
Originally Posted by bushidozen
I just looked over your code, and I saw a couple of errors, so I rewrote it a little:
# Replace upper case with lower case
# Replace spaces with underscores
import os, sys
if len(sys.argv) == 1:
filenames = os.listdir(os.curdir)
filenames = sys.argv[1:]
for filename in filenames:
newfilename = filename.lower()
if ' ' in newfilename:
newfilename = newfilename.replace(' ', '_')
print "Renaming", filename, "to", newfilename, "..."
This code will attempt to convert all filenames to lowercase (even those that are already lowercase), which could translate into a lot of wasted cycles (ie. if all of the files in the directory are already lowercase), but it actually runs faster than trying to determine its case as in the previous code (by using the if statement). Enjoy.