linux zip Invalid encoding

脚本myunzip.py

#!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():
    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()

解压文件时,直接执行:

$ python myunzip.py xxx.zip

或者,先增加可执行权限,然后执行:

$ chmod +x myunzip.py
$ ./myunzip.py xxx.zip

转自:https://www.jianshu.com/p/35369813826a

Leave a Reply