Sourceinsight does not support UTF-8. to support Chinese display, write a python applet to transcode all files in a directory from UTF-8 to gbk as follows :#! Usrlocalbinpython #-*-coding: UTF-8-*-sourceinsight does not support UTF-8. to support Chinese display, this program transcodes all files in a directory from UTF-8... source insight does not support UTF-8. to support Chinese display, write a python applet to transcode all files in a directory from UTF-8 to gbk.
The code is as follows:
#!/usr/local/bin/python# -*- coding: utf-8 -*-'''
Source insight does not support UTF-8. to support Chinese display, write this program.
Transcode all files in a directory from UTF-8 to gbk
usage: chmod +x convert.py./convert.py src mysrc'''import osimport shutilimport reimport sys #####################################def search(src,dest,handler): filelist=os.listdir(src) for f in filelist: cf=src+'/'+f df=dest+'/'+f if os.path.isdir(cf): if not os.path.exists(df):os.makedirs(df) search(cf,df,handler) else: handler(cf,df)#the function dealing with file########################################################## def convertFile(sfn,dfn): sf=open(sfn,'r') s=sf.read() try: s=s.decode('utf-8') df=open(dfn,'w') df.write(s.encode('gbk')) df.flush() sf.close() df.close() print '*** ',sfn except: sf.close() print sfn sys.exit() if name == 'main':srcDir=os.getcwd()+'/'+sys.argv[1]dstDir=os.getcwd()+'/'+sys.argv[2]search(srcDir,dstDir,convertFile)
The above is the content of the file transcoding tool written in python. For more information, see PHP Chinese network (www.php1.cn )!