Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Created August 3, 2010 01:23
Show Gist options
  • Save huacnlee/505670 to your computer and use it in GitHub Desktop.
Save huacnlee/505670 to your computer and use it in GitHub Desktop.
# Linux 遍历目录下面所有文件,将文件名转为小写
#!/usr/bin/python
# the following script will traverse through all of the files
# within the directory where it is placed and replace each
# underscore within the filename with a space
import os, sys,re
print "Auto convert Upper filename to Lower filename"
dir = '/home/huacnlee/uploadfiles'
print "find files..."
for root,dirs,files in os.walk(dir):
print root
print str(len(files)) + " found."
os.rename(root,root.lower())
for f in files:
filename = root.lower() + "/" + f
if re.search('[A-Z]',filename) != None:
print filename
newfilename = filename.lower()
print "Renaming", f, "to", f.lower(), "..."
os.rename(filename, newfilename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment