关于解压文档名中文出现乱码解决方案

来源:互联网 发布:java程序开发培训价格 编辑:程序博客网 时间:2024/06/10 00:26

用例

在linux中解压文件后,出现文件名的中文不能正常的显示。

静态

动态

1 在待解压的文件夹下新增文件

vi unzip.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()

2 保存后执行如下命令

python unzip.py *.zip

0 0
原创粉丝点击