使用场景:
某工程下的代码文件中存在重复引用头文件的情况,现在需要找到这些文件,并将问题文件以及重复引用的头文件输出。
import os
import re
from collections import Counter
from collections import defaultdict
import chardet
import json
desDir = "D:/XX" #请配置需要扫描的目录
DupHeaderFiles=[]
file_list = defaultdict(list)
# 获取文件编码类型
def get_encoding(file):
# 二进制方式读取,获取字节数据,检测类型
with open(file, 'rb') as f:
data = f.read()
return(chardet.detect(data)['encoding'])
# 查重
def find_Dup(fileName):
code=get_encoding(fileName)
f=open(fileName,'r',encoding=code)
hasDup = False
lines=f.read