Source Insight unexpectedly does not support utf-8, in order to support the Chinese display, so write a Python applet will be a directory of all files from the Utf-8 transcoding to GBK
The code is as follows:
#!/usr/local/bin/python#-*-coding:utf-8-*-""
Source Insight unexpectedly does not support utf-8, in order to support the Chinese display, so write the 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 (d f): 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.C Lose () 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,DST Dir,convertfile)
The above is the Python written file transcoding gadget content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!