Skip to content

Instantly share code, notes, and snippets.

@bcjarrett
Created August 8, 2018 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcjarrett/76d3a1f36e6c9974bb00f41388c1a56b to your computer and use it in GitHub Desktop.
Save bcjarrett/76d3a1f36e6c9974bb00f41388c1a56b to your computer and use it in GitHub Desktop.
The laziest way to fix special characters in folder names
import os
folder = ''
x = True
while x:
renameables = []
for root, dirs, _ in os.walk(folder):
for d in dirs:
dir_name = (os.path.join(root, d))
renameables.append(dir_name)
if renameables:
for i in renameables:
try:
os.rename(i, i.replace(',', '_'))
except (FileNotFoundError, PermissionError):
print(i)
pass
else:
x = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment