Linux解压zip中文乱码

某些时候在windows上打包的zip文件中有中文文件名,在Linux上用unzip -O解压会出现中文乱码情况。以下为解压脚本,不会乱码:

#!/usr/bin/env python
# -*- 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():  
    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()  

使用:zip文件跟这个py文件放在同一级目录,运行命令python pyzip.py file.zip即可。