|
@@ -49,7 +49,10 @@ def convert_encoding_in_dir(directory, dest_encoding, extensions):
|
|
|
for file_path in tqdm(files_to_process, desc="转换文件编码进度", unit="文件"):
|
|
|
try:
|
|
|
# 自动检测文件编码
|
|
|
- src_encoding = detect_file_encoding(file_path)
|
|
|
+ # src_encoding = detect_file_encoding(file_path)
|
|
|
+ src_encoding = "GB2312"
|
|
|
+ # if src_encoding == 'MacRoman' or src_encoding == 'ascii':
|
|
|
+ # src_encoding = "GB2312"
|
|
|
|
|
|
# 读取并转换文件内容
|
|
|
with open(file_path, 'r', encoding=src_encoding, errors='ignore') as f:
|
|
@@ -68,7 +71,7 @@ def convert_encoding_in_dir(directory, dest_encoding, extensions):
|
|
|
|
|
|
|
|
|
# 示例调用
|
|
|
-directory = "./都市生活" # 替换为你的目标文件夹路径
|
|
|
+directory = "./全书" # 替换为你的目标文件夹路径
|
|
|
dest_encoding = "utf-8"
|
|
|
extensions = ['.txt', '.html', '.htm', '.js'] # 需要处理的文件扩展名
|
|
|
convert_encoding_in_dir(directory, dest_encoding, extensions)
|