1 Star 0 Fork 0

no2key/ToughRadius

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
batch2utf8.py 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
jamiesun 提交于 2013-08-31 17:55 . add build script
#!/usr/bin/python
#codeing:utf-8
import os
from optparse import OptionParser
def convutf8(chdir,cext):
if not chdir:chdir = '.'
if not cext:raise Exception('no file ext')
for base,sub,files in os.walk(chdir):
for fd in files:
fpath = os.path.join(base,fd)
if fd.endswith(cext):
try:
rfd = open(fpath,'rb')
print 'read gbk file',fd
gbk_src = rfd.read().decode('gbk')
rfd.close()
wfd = open(fpath,'wb')
print 'write utf8 file',fd
utf8_src = gbk_src.encode('utf-8')
if utf8_src:
wfd.write(utf8_src)
except Exception,e:
print e
print 'already utf-8'
if __name__ == "__main__":
usage = "usage: %prog [options] arg"
parser = OptionParser(usage)
parser.add_option("-p", "--path", dest="path",help="files path")
parser.add_option("-e", "--ext",dest="ext", help="file ext")
(options, args) = parser.parse_args()
convutf8(options.path,options.ext)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/no2key/toughradius.git
[email protected]:no2key/toughradius.git
no2key
toughradius
ToughRadius
master

搜索帮助