红联Linux门户
Linux帮助

RedHat Linux 6.0中文编码问题

发布时间:2014-11-12 09:29:49来源:linux网站作者:sudongyuan

RedHat Linux 6.0 中文编码问题描述:

FTP传一个中文压缩文件上服务器,若是ZIP文件中存在中文文件名,则解压出来会乱码。


解决办法:

把以下脚本保存成unzipgbk.py,存放于/bin目录下,解压时候用类似以下的命令:unzipgbk 中文名称.zip

#!/usr/bin/env python
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()
[root@localhost bin]# more unzipgbk
if [ $# -ne 1 ] ; then
echo "Usage testabc filename"
exit 0;
fi;

echo "argument is " $1
python /bin/unzipgbk.py $1