Linux,centos解压ZIP中文名称乱码

admin 2017-12-27 2668

 

最近碰到这个问题,网上搜了一圈,都是什么unzip -O,一点用都没有,这些哥们估计是直接复制,用都没用过。

后来找了个终极方法,用python的脚本来解压,试了下,还真管用!!!

以下为python脚本的代码,新建文件jieya.py,写入以下代码:

=============================================================

#!/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文件跟jieya.py放在同一级目录,运行命令python  jieya.py file.zip,哦了!

转账来自:http://m.blog.csdn.net/u014447386/article/details/23511535

温馨提示:

python解决方案虽然好用,但是最好不要用,简单的处理会有很多风险,比如zip炸弹,目录覆盖,执行病毒文件等。

正确的做法是:尽量使用英文,解压自己的文件是没什么问题的,网络上的文件尽量不要使用本方法解压


最新回复 [0]
返回