Last active
December 4, 2022 11:33
-
-
Save xgdgsc/5967294 to your computer and use it in GitHub Desktop.
python script to extract zip with GBK encoding
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 -*- | |
# file: unzip.py | |
import zipfile,os,sys | |
if len(sys.argv)==2: | |
fname=sys.argv[1] | |
else: | |
print "Usage: python %s filename\n\n" % sys.argv[0] | |
sys.exit() | |
if (not os.path.exists(fname)) or (not zipfile.is_zipfile(fname)): | |
print fname,"is not zipfile or not exists" | |
sys.exit() | |
f=zipfile.ZipFile(fname) | |
for finfo in f.infolist(): | |
savename=unicode(finfo.filename,'GBK') | |
if os.path.exists(savename):continue | |
if finfo.file_size==0: | |
os.mkdir(savename) | |
else: | |
of=open(savename,'w') | |
of.write(f.read(finfo)) | |
of.close() | |
print savename | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment