ANSI编码的文件转为UTF-8编码的文件。
# ANSI文件转UTF-8 import codecs import os # 文件所在目录 file_path = "H:\Python\South.Park.S02.WEB-DL.chs" files = os.listdir(file_path) for file in files: file_name = file_path + ‘\\‘ + file f = codecs.open(file_name, ‘r‘, ‘ansi‘) ff = f.read() file_object = codecs.open(file_path + ‘\\‘ + file, ‘w‘, ‘utf-8‘) file_object.write(ff)
时间: 2024-10-29 15:36:35