Skip to content

Instantly share code, notes, and snippets.

@javiercantero
Created March 12, 2012 16:28
Show Gist options
  • Save javiercantero/2023173 to your computer and use it in GitHub Desktop.
Save javiercantero/2023173 to your computer and use it in GitHub Desktop.
recursively rename all the files and subdirs of current dir to lowercase
#!/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('.')
@javiercantero
Copy link
Author

Piensa que era una ñapa rápida para salir del paso... O:-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment