文本UTF8检查工具

上一篇 / 下一篇  2020-12-22 09:51:10 / 个人分类:测试技术

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
# @Time : 2020/7/10 13:52 
# @Author : zhixiongg
# @Site :  
# @File : utf8.py 
# @Software: PyCharm

import os
from chardet import detect


def listdir(path, list_name):  # 传入存储的list
    for file in os.listdir(path):
        file_path = os.path.join(path, file)
        if os.path.isdir(file_path):
            listdir(file_path, list_name)
        elif (file_path.endswith('.cpp') or file_path.endswith('.h') or file_path.endswith('.c')):  # 处理的文件后缀
            list_name.append(file_path)
    return list_name


filePath = input("请输入需要处理的文件夹路径:")
#filePath = 'C:\\Users\\zhixiongg\\Desktop\\EntierDbAPI'

fns = []
fns = listdir(filePath, fns)

for fn in fns:
    with open(fn, 'rb+') as fp:
        content = fp.read()
        codeType = detect(content)['encoding']

        if (codeType != 'utf-8' and content != b''):  # 跳过空文件
            print(fn, ":编码格式为:",codeType ,",请修改!")
print('检查完毕!')


TAG:

 

评分:0

我来说两句

我的栏目

日历

« 2024-03-25  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 1410
  • 日志数: 5
  • 建立时间: 2018-12-12
  • 更新时间: 2020-12-22

RSS订阅

Open Toolbar