Created
August 8, 2018 16:14
-
-
Save bcjarrett/76d3a1f36e6c9974bb00f41388c1a56b to your computer and use it in GitHub Desktop.
The laziest way to fix special characters in folder names
This file contains hidden or 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 | |
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