Skip to content

Instantly share code, notes, and snippets.

@usunyu
Created October 24, 2016 09:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usunyu/dfc6e56af6e6caab8018bef4c3f3d452 to your computer and use it in GitHub Desktop.
Save usunyu/dfc6e56af6e6caab8018bef4c3f3d452 to your computer and use it in GitHub Desktop.
解决unzip中文乱码问题
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# unzip-gbk.py
import os
import sys
import zipfile
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()
@usunyu
Copy link
Author

usunyu commented Oct 24, 2016

python gbk-unzip.py file.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment