Skip to content

Instantly share code, notes, and snippets.

@idolpx
Last active October 31, 2025 17:04
Show Gist options
  • Save idolpx/6b0fb11f5f409efbddd3f76703b582e6 to your computer and use it in GitHub Desktop.
Save idolpx/6b0fb11f5f409efbddd3f76703b582e6 to your computer and use it in GitHub Desktop.
Rename all files and folders recursively from current directory to lowercase
#!/usr/local/bin/python3
import os
list = []
dirlist = [os.getcwd() + '/']
# Build recursive list for dirs and files
while len(dirlist) > 0:
for (dirpath, dirnames, filenames) in os.walk(dirlist.pop()):
dirlist.extend(dirnames)
list.extend( map(lambda n: os.path.join(*n), zip([dirpath] * len(dirnames), dirnames)) )
list.extend( map(lambda n: os.path.join(*n), zip([dirpath] * len(filenames), filenames)) )
# Iterate through list backwards and rename files and folders
for x in range(len(list) -1, -1, -1):
item = list[x]
print(f'{item} >>> {item.lower()}')
os.rename(item, item.lower())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment