Skip to content

Instantly share code, notes, and snippets.

@zhanghai
Created July 5, 2014 11:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zhanghai/3dbc328b150fced76ca1 to your computer and use it in GitHub Desktop.
Save zhanghai/3dbc328b150fced76ca1 to your computer and use it in GitHub Desktop.
Python script that can unzip filename with gbk encoding correctly.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# unzip-gbk.py
import os
import sys
import zipfile
print u"正在处理压缩文件 %s" % sys.argv[1].decode('utf-8')
print
file = zipfile.ZipFile(sys.argv[1], "r")
for gbkname in file.namelist():
utf8name = gbkname.decode('gbk')
print u"正在提取 %s" % utf8name
pathname = os.path.dirname(utf8name)
if not os.path.exists(pathname) and pathname != "":
os.makedirs(pathname)
if not os.path.exists(utf8name):
data = file.read(gbkname)
outfile = open(utf8name, "w")
outfile.write(data)
outfile.close()
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment