Skip to content

Instantly share code, notes, and snippets.

@amiraliakbari
Created April 16, 2015 13:45
Show Gist options
  • Save amiraliakbari/3db0503985e9ee81c555 to your computer and use it in GitHub Desktop.
Save amiraliakbari/3db0503985e9ee81c555 to your computer and use it in GitHub Desktop.
Fix special characters in filenames
#!/usr/bin/env python
def rr(dir):
for d in os.listdir(dir):
dd = d.replace('\xef\x80\xa2', '-')
if d != dd:
os.rename(os.path.join(dir, d), os.path.join(dir, dd))
child = os.path.join(dir, dd)
if os.path.isdir(child):
rr(child)
rr('/home/Morteza/Downloads/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment