Created
July 24, 2011 19:57
-
-
Save iveney/1103025 to your computer and use it in GitHub Desktop.
Rename files that have GBK encoded filenames but wrongly encoded in UTF8
This file contains 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 | |
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