Created
July 5, 2014 11:12
-
-
Save zhanghai/3dbc328b150fced76ca1 to your computer and use it in GitHub Desktop.
Python script that can unzip filename with gbk encoding correctly.
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 | |
# -*- coding: utf-8 -*- | |
# unzip-gbk.py | |
import os | |
import sys | |
import zipfile | |
print u"正在处理压缩文件 %s" % sys.argv[1].decode('utf-8') | |
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