UTF8文件去BOM,UTF8文件BOM,[Python]代码#!
UTF8文件去BOM,UTF8文件BOM,[Python]代码#!
[Python]代码
#!/usr/bin/python#coding=utf-8import osimport sysimport codecsclass RemoveBom: basePath = '' fileList = [] trimExtList = [] def showMessages(self): print 'the Path is [',self.basePath,']' n = '' for ext in self.trimExtList: n+=ext n+=' ' print 'the Exts is [' ,n,']' def trimFile(self,name): file = open(name,'rb') content = file.read(3) if content != '\xEF\xBB\xBF': return False content = file.read() file.close() file = open(name,'wb') file.write(content) file.close print 'convert ',name,' finish' return True def getFileList(self,path): if not path: return False for root,dirs,files in os.walk(path): for filename in files: if filename.split('.')[-1] in self.trimExtList: filepath=os.path.join(root,filename) self.trimFile(filepath) #print filepath def run(self,argv): self.basePath = os.path.normpath(argv[1]) if len(argv) < 3: self.trimExtList.append('java') else: for i in range(len(argv)-2): self.trimExtList.append(argv[2+i]) self.showMessages() self.getFileList(argv[1])if __name__ == '__main__': if len(sys.argv) < 2: print 'USEAGE:python %s dirName [ext eg:java php cpp]' % __file__ sys.exit(0) tObj = RemoveBom() tObj.run(sys.argv)
相关内容
- python使用sha1加密方法验证文件的有效性,,import hashl
- 批量去除UTF8的Bom标签,utf8bom标签,#!/usr/bin/p
- 周长画圆,周长,[Python]代码im
- for循环,,[Python]代码ki
- 格式化数字及其单位,格式化数字单位,[Python]代码de
- python socket单工聊天工具,pythonsocket单工,socket单工聊天
- 用Python编写的列举所有对称日的小程序--菜鸟写的,请
- python监控网卡流量,python监控网卡,[Python]代码im
- Find the coefficients of the polynomial that fits the specified data
- tinyipdate最新ip库 python操作类,tinyipdatepython,发布最新版
评论关闭