歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> RedHat Linux 6.0 中文編碼問題

RedHat Linux 6.0 中文編碼問題

日期:2017/2/28 15:50:42   编辑:Linux教程

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

更多RedHat相關信息見RedHat 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=10

Copyright © Linux教程網 All Rights Reserved