批量将gbk文件转换成utf-8

2015-08-11 0 895
批量将gbk文件转换成utf-8
#!/usr/bin/python
#coding=utf-8
import sys
import os, os.path
import dircache
import commands
def add(x,y):
    return x*y

def trans(dirname):
    lis = dircache.opendir(dirname)
    for a in lis:
        af=dirname+os.sep+a
##        print af
        if os.path.isdir(af):
##            print af
            trans(af)
        else:
    ##        print af+"encoding="+fi.name
            ft = commands.getoutput('file -i '+af)
##            print ft
            if a.find('.htm')==-1 and a.find('.xml')==-1 and ft.find('text/')!=-1 and ft.find('iso-8859')!=-1:
                print 'gbk'+ft+"   >"+af
                commands.getoutput('iconv -ficonv -f gbk -t utf-8 -c -o'+" "+af+" "+af)

trans(os.getcwd())

遇见资源网 python 批量将gbk文件转换成utf-8 http://www.ox520.com/15674.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务