Skip to content

Instantly share code, notes, and snippets.

@burgil
Created April 21, 2024 22:45
Show Gist options
  • Save burgil/d47ad19be6f61fd15e45d82b681cd873 to your computer and use it in GitHub Desktop.
Save burgil/d47ad19be6f61fd15e45d82b681cd873 to your computer and use it in GitHub Desktop.
Mass remove spaces from folders in the current directory using python - Use `python "folder space cleaner.py"` and all the folders in the *current directory will be renamed and the spaces will be removed
import os
def remove_spaces_from_folders():
current_dir = os.getcwd()
folders = [f for f in os.listdir(current_dir) if os.path.isdir(os.path.join(current_dir, f))]
for folder in folders:
if ' ' in folder:
new_name = folder.replace(' ', '')
os.rename(os.path.join(current_dir, folder), os.path.join(current_dir, new_name))
print(f"Renamed '{folder}' to '{new_name}'")
if __name__ == "__main__":
remove_spaces_from_folders()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment