Skip to content

Instantly share code, notes, and snippets.

@iveney
Created July 24, 2011 19:57
Show Gist options
  • Save iveney/1103025 to your computer and use it in GitHub Desktop.
Save iveney/1103025 to your computer and use it in GitHub Desktop.
Rename files that have GBK encoded filenames but wrongly encoded in UTF8
#!/usr/bin/env python
import sys
import os
import unicodedata
for name in sys.argv[1:]:
try:
new_name = unicodedata.normalize("NFC", name.decode('utf8'))
new_name = new_name.encode('latin-1').decode('gbk')
new_name_utf8 = new_name.encode('utf8')
if name != new_name_utf8:
print "%s -> %s" % (name, new_name_utf8)
#os.rename(name, new_name)
except:
print "Ignoring %s" % name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment