Created
March 25, 2021 10:05
-
-
Save adityasatalkar/da81eea0ae8bcee9265b2deba59c23ad to your computer and use it in GitHub Desktop.
List all sub-directories in a dir and rename them to lower case, while replacing spaces with "-"
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
import os | |
path = '/Users/username/Documents/example-folder/' | |
def replace(): | |
directory_contents = os.listdir(path) | |
for name in directory_contents: | |
if os.path.isdir(path + name): | |
file_path = os.path.join(path, name) | |
new_name = os.path.join(path, name.lower().strip().replace(" ", "-")) | |
print(new_name) | |
os.rename(file_path, new_name) | |
replace() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment