Skip to content

Instantly share code, notes, and snippets.

@zxteloiv
Created December 21, 2015 10:25
Show Gist options
  • Save zxteloiv/fe429ed3817511366283 to your computer and use it in GitHub Desktop.
Save zxteloiv/fe429ed3817511366283 to your computer and use it in GitHub Desktop.
unzip in another encoding
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import os
import sys
import zipfile
if len(sys.argv) == 1:
sys.exit(0)
print "Processing File " + sys.argv[1]
file = zipfile.ZipFile(sys.argv[1],"r");
for name in file.namelist():
utf8name = name.decode('gbk')
print "Extracting " + utf8name
pathname = os.path.dirname(utf8name)
if not os.path.exists(pathname) and pathname!= "":
os.makedirs(pathname)
data = file.read(name)
if not os.path.exists(utf8name):
fo = open(utf8name, "w")
fo.write(data)
fo.close
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment