Skip to content

Instantly share code, notes, and snippets.

@insolor
Last active December 14, 2020 06:46
Show Gist options
  • Save insolor/f2c25fda065f594ad6c0e5e445e38dc7 to your computer and use it in GitHub Desktop.
Save insolor/f2c25fda065f594ad6c0e5e445e38dc7 to your computer and use it in GitHub Desktop.
Rename files and directories to lower case recursively depht-first in python
from pathlib import Path
# WARNING: Renaming is an irreversible operation, so it is better to use an absolute path
for path in sorted(Path('~/some_directory').rglob('*'), key=lambda p: len(p.parts), reverse=True):
# Rename and print new name
print(path.rename(path.with_name(path.name.lower())))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment