码迷,mamicode.com
首页 > 系统相关 > 详细

解决Linux下zip文件解压乱码问题

时间:2016-11-14 01:19:57      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:port   exists   utf8   div   cti   linux   odi   close   dir   

 

 

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

 

作者:Latm Ake
链接:https://www.zhihu.com/question/20523036/answer/35225920
来源:知乎
著作权归作者所有

解决Linux下zip文件解压乱码问题

标签:port   exists   utf8   div   cti   linux   odi   close   dir   

原文地址:http://www.cnblogs.com/xmzncc/p/6060185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!