Created
November 19, 2018 23:26
-
-
Save kyuumeitai/d11644e13f0b08f097d217a57f0c1e37 to your computer and use it in GitHub Desktop.
convert unicode filenames to pure ascii
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
#!/usr/bin/env python | |
# convert unicode filenames to pure ascii | |
import os | |
import sys | |
import glob | |
import unicodedata | |
EXT = u'*.*' | |
def remove_accents(s): | |
nkfd_form = unicodedata.normalize('NFKD', s) | |
return u''.join([c for c in nkfd_form if not unicodedata.combining(c)]) | |
for fname in glob.glob(EXT): | |
new_fname = remove_accents(fname) | |
if new_fname != fname: | |
try: | |
print 'renaming non-ascii filename to', new_fname | |
os.rename(fname, new_fname) | |
except Exception as e: | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment