Created
October 14, 2021 21:01
-
-
Save john-sandall/ed6bbb8ba749bcc162bc73118709dc8f to your computer and use it in GitHub Desktop.
Rename files & folders in current 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
# In IPython, you can change the current working directory using | |
# %cd /path/to/some/directory/ | |
import os | |
from pathlib import Path | |
# Directory containing folders you want to rename | |
here = Path(".") # "." means "the current directory" | |
# Loop through all the folders & files in this directory | |
for current_name in os.listdir(): | |
# Remove spaces & lowercase | |
new_name = current_name.replace(" ", "_").lower() | |
# Rename each file/folder | |
os.rename(here / current_name, here / new_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment