注意: 如果是linux下压缩的 zip文件,不用一下方法,直接用unzip命令即可。
拷贝一下内容,并将其粘帖至 /usr/bin/uzip
添加执行权限: chmod +x /usr/bin/uzip
解压命令: uzip 文件名.zip (不是unzip哦)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# uzip.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()
|