zoukankan      html  css  js  c++  java
  • py2.7 批量转换文件为 utf8 编码

    source insight 不支持 utf8 ,但是在 linux 上查看的时候是 utf8 编码,就会显示不正常,所以写了个 python 小脚本,可以批量转换

    py2.7

     1 #coding:utf-8
     2 '''
     3 GBK 转 UTF-8 工具
     4 author: 宁次
     5 date  :2017-02-03 19:58
     6 用法:python toutf8.py d:/wwwwroot
     7 '''
     8 import sys
     9 import os
    10 #要转换的文件类型
    11 exts = ('.c', '.cpp', '.s', '.S', '.lds', '.h', 'Makefile')
    12 if 2 > len(sys.argv):
    13     print 'usage:python toutf8.py d:/wwwroot'
    14     sys.exit()
    15 #命令行传来的需要处理的路径    
    16 path = sys.argv[1]
    17 for root, dirs, files in os.walk(path):
    18     for name in files:
    19         ext = os.path.splitext(name)[1]
    20         if ext in exts:
    21             file = os.path.join(root, name)
    22             with open(file, 'r+') as f:
    23                 data = f.read()
    24                 data = data.decode('GBK').encode('UTF-8')
    25                 f.seek(0)
    26                 f.write(data)
    27 
    28         
  • 相关阅读:
    内联汇编的使用
    metamask注记词
    一个简单的增删改查合约
    企业邮箱账号
    压缩包管理
    设计模式
    软硬链接ln
    文件IO-Linux
    静态库和动态库
    gdb调试
  • 原文地址:https://www.cnblogs.com/ningci/p/6363369.html
Copyright © 2011-2022 走看看