Last active
December 23, 2015 17:39
-
-
Save PeterDing/6670254 to your computer and use it in GitHub Desktop.
[转]:http://wangqige.com/the-solution-of-unzip-files-which-zip-under-windows/解决在Linux环境下解压zip的乱码问题 -- # 移到仓库 https://github.com/PeterDing/iScript
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 python2 | |
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
import zipfile | |
print "Processing File " + sys.argv[1] | |
file=zipfile.ZipFile(sys.argv[1],"r"); | |
for name in file.namelist(): | |
try: | |
utf8name=name.decode('gbk') | |
pathname = os.path.dirname(utf8name) | |
except: | |
utf8name=name | |
pathname = os.path.dirname(utf8name) | |
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): | |
try: | |
fo = open(utf8name, "w") | |
fo.write(data) | |
fo.close | |
except: | |
pass | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment