coding = "utf-8"
import os
import glob
import chardet
path = "E://xxx"
for root_path,dir_name,file_name in os.walk(path):
for file in file_name:
if file.endswith("php"):
ture_file = os.path.join(root_path,file)
print(ture_file)
with open(ture_file,'rb') as out_file:
data = out_file.read()
chr_res = chardet.detect(data)
print(chr_res)
# if chr_res['encoding']=="GB2312":
# data = data.decode("gbk")
# else:
try:
data = data.decode(chr_res['encoding'])
except:
data = data.decode("gbk")
with open(ture_file,'wb') as f:
f.write(data.encode("utf-8"))