Last active
September 4, 2018 09:46
-
-
Save deeuu/6ac5d84349e425e50025518037126661 to your computer and use it in GitHub Desktop.
Python function to lower case all sub-directories and files in a directory
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
def lower_case_all(dirname): | |
import os | |
for dirpath, dirs, files in os.walk(dirname, topdown=False): | |
for filename in files: | |
os.rename(os.path.join(dirpath, filename), | |
os.path.join(dirpath, filename.lower())) | |
for adir in dirs: | |
os.rename(os.path.join(dirpath, adir), | |
os.path.join(dirpath, adir.lower())) | |
os.rename(dirname, dirname.lower()) | |
def lower_case_all_pathlib(dirname): | |
''' | |
Same but using pathlib | |
''' | |
import pathlib | |
for path in dirname.rglob('*'): | |
path.rename(path.parent / path.name.lower()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment