别问有啥用,懂得都懂/(ㄒoㄒ)/~~
import os
import chardet
charset={}
def getEncoding(file):
with open(file, 'rb') as f:
data = f.read()
return chardet.detect(data)['encoding']
def openOrCount(path):
files= os.listdir(path)
for file in files:
if os.path.isdir(path + '/' + file):
openOrCount(path + '/' + file)
else:
encode = getEncoding(path + '/' + file)
if encode in charset:
charset[encode] += 1
else:
charset[encode] = 1
openOrCount("D:/project/myProject")
print(charset)