浙江省高等学校教师教育理论培训

微信搜索“教师资格证岗前培训”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

#!/usr/bin/env python
#encoding=gbk
import sys
reload(sys)
sys.setdefaultencoding("gbk")

"""
将指定目录下的所有文件从utf-8转换到gbk

主要用于查看sourceinsight的代码

sourceinsight需要gbk,utf-8会乱码


"""
import codecs,os,os.path
def utf8_to_gbk(file):
    print file
    originals=codecs.open(file,"r","utf-8").readlines()
    f=codecs.open(file,"w","gbk")
    for line in originals:
        f.write(line.encode("gbk","ignore"))
    f.close()

def walk(path):
     for root, dirs, files in os.walk(path):
        for file in files:
            utf8_to_gbk(os.path.join(root,file))

if __name__ == '__main__':
    #file=ur"C:\mao\code\trunk\query\QueryServer\src\PinYin.h"
    #print file
    #utf8_to_gbk(file)
    walk(r"C:\mao\code\trunk\query\QueryServer\src")

posted on 2013-02-26 11:13  lexus  阅读(318)  评论(0编辑  收藏  举报