Last active
December 14, 2020 06:46
-
-
Save insolor/f2c25fda065f594ad6c0e5e445e38dc7 to your computer and use it in GitHub Desktop.
Rename files and directories to lower case recursively depht-first in python
This file contains hidden or 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
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