Geek · 2013/08/27 0

Ubuntu 下解压 windows(GBK文件名) 压缩包的脚本

360doc 上找到的, 稍微改了一点点, 有效可用, python脚本
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import zipfile

print "Processing File " + sys.argv[1]

f = zipfile.ZipFile(sys.argv[1], "r")
for name in f.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 = f.read(name)
    if not os.path.exists(utf8name):
        fo = open(utf8name, "wb")
        fo.write(data)
        fo.close
f.close()