# IPython log file
import chardet
import os
def getEncoding(file_name):
with open(file_name, 'rb') as f:
return chardet.detect(f.read())['encoding']
def file2utf8():
L = [i for i in os.listdir() if os.path.splitext(i)[-1] in ['.txt', '.py'] and os.path.isfile(i)]
if not os.path.exists('outdir'):
os.mkdir('outdir')
if not os.path.exists('report'):
os.mkdir('report')
for file_name in L:
with open(file_name, 'r', encoding = getEncoding(file_name)) as f:
s = f.read()
with open(os.path.join('outdir',file_name), 'w', encoding = 'utf-8') as f:
f.write(s)
with open(os.path.join('report','report.txt'),'w',encoding='utf-8') as f:
for i in L:
f.write(' '.join([i,getEncoding(i),'\n']))
if __name__=='__main__':
file2utf8()