# -*- coding: utf-8 -*- #encoding=utf-8 import os import codecs def utf8 (path): f = open(path,"r") s = f.read() f.close() if s.startswith(codecs.BOM_UTF8): s = s[len(codecs.BOM_UTF8):] f = open(path, "w") f.write(s) f.flush() f.close() def getListFiles(path): assert os.path.isdir(path), '%s not exist.' % path ret = [] for root, dirs, files in os.walk(path): #print '%s, %s, %s' % (root, dirs, files) for filespath in files: ret.append(os.path.join(root,filespath)) return ret ret = getListFiles('d:\src')//源码的目录 print len(ret) for f in ret: print f,"\n" utf8(f)
UTF-8编码去掉BOM头方法
最新推荐文章于 2022-01-23 00:57:33 发布