Created
March 12, 2012 16:28
-
-
Save javiercantero/2023173 to your computer and use it in GitHub Desktop.
recursively rename all the files and subdirs of current dir to lowercase
This file contains 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
#!/usr/bin/python | |
# | |
# rename-lowercase.py | |
# | |
# recursively rename all the files and subdirs of current dir to lowercase | |
# (for example, from an old MS-DOS .zip) | |
# | |
# renombra recursivamente todos los ficheros y subdirectorios del directorio | |
# actual a minusculas (por ejemplo, proveniente de un antiguo .zip de MS-DOS) | |
# | |
import os | |
def rename_dir_to_lowercase(dir): | |
dir_entries = os.listdir(dir) | |
for dir_entry in dir_entries: | |
old_name = os.path.join(dir, dir_entry) | |
new_name = os.path.join(dir, dir_entry.lower()) | |
if os.path.isfile(old_name): | |
print "Renombrando %s a %s" % ( old_name, new_name ) | |
#print "Renaming from %s to %s" % ( old_name, new_name ) | |
os.rename( old_name, new_name ) | |
elif os.path.isdir(old_name): | |
print "Entrando en %s" % (old_name) | |
#print "Entering into %s" % (old_name) | |
rename_dir_to_lowercase( old_name ) | |
print "Renombrando %s a %s" % ( old_name, new_name ) | |
#print "Renaming from %s to %s" % ( old_name, new_name ) | |
os.rename( old_name, new_name ) | |
else: | |
print "%s no es un fichero o directorio" % (old_name) | |
#print "%s is not a file or dir" % (old_name) | |
# You can change '.' to the path you prefer | |
# Puedes cambiar '.' al directorio de tu eleccion | |
rename_dir_to_lowercase('.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Piensa que era una ñapa rápida para salir del paso... O:-)