36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
# 批量修复多个文件的BOM字符
|
|
import os
|
|
|
|
# 要修复的文件列表
|
|
files_to_fix = [
|
|
'd:\\code\\PriceForecast-svn\\main_juxiting.py',
|
|
'd:\\code\\PriceForecast-svn\\main_juxiting_yuedu.py',
|
|
'd:\\code\\PriceForecast-svn\\main_juxiting_zhoudu.py',
|
|
'd:\\code\\PriceForecast-svn\\main_yuanyou.py',
|
|
'd:\\code\\PriceForecast-svn\\main_yuanyou_yuedu.py',
|
|
'd:\\code\\PriceForecast-svn\\main_yuanyou_zhoudu.py'
|
|
]
|
|
|
|
# 修复文件中的BOM字符
|
|
fixed_files = 0
|
|
for file_path in files_to_fix:
|
|
try:
|
|
# 读取文件(二进制模式)
|
|
with open(file_path, 'rb') as f:
|
|
content = f.read()
|
|
|
|
# 检查并移除BOM字符
|
|
if content.startswith(b'\xef\xbb\xbf'):
|
|
content = content[3:]
|
|
# 写回文件
|
|
with open(file_path, 'wb') as f:
|
|
f.write(content)
|
|
print(f"已修复BOM: {file_path}")
|
|
fixed_files += 1
|
|
else:
|
|
print(f"无BOM: {file_path}")
|
|
except Exception as e:
|
|
print(f"修复文件失败 {file_path}: {e}")
|
|
|
|
# 输出总结
|
|
print(f"\n已修复{fixed_files}个文件的BOM字符。") |