Skip to content

Instantly share code, notes, and snippets.

@beddari
Created October 17, 2018 06:33
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 beddari/28c5ba53976eddc67edf997b5f5d9e25 to your computer and use it in GitHub Desktop.
Save beddari/28c5ba53976eddc67edf997b5f5d9e25 to your computer and use it in GitHub Desktop.
ascii filenames
#!/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