RedHat Chinese encoding in Linux 6.0
RedHat Linux 6.0 Chinese encoding Problem description:
FTP transfers a Chinese compressed file to the server. If the ZIP file contains a Chinese file name, unzipping will cause garbled characters.
Solution:
Save the following script as unzipgbk. py and store it in the/bin directory. Run the following command: unzipgbk Chinese name. 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
For more information about RedHat, see RedHat topic page http://www.bkjia.com/topicnews.aspx? Tid = 10