34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
# 检查多个文件是否存在BOM字符
|
|
import os
|
|
|
|
# 要检查的文件列表
|
|
files_to_check = [
|
|
'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字符
|
|
files_with_bom = []
|
|
for file_path in files_to_check:
|
|
try:
|
|
with open(file_path, 'rb') as f:
|
|
content = f.read(3) # 只读取前3个字节
|
|
if content.startswith(b'\xef\xbb\xbf'):
|
|
files_with_bom.append(file_path)
|
|
print(f"发现BOM: {file_path}")
|
|
else:
|
|
print(f"无BOM: {file_path}")
|
|
except Exception as e:
|
|
print(f"检查文件失败 {file_path}: {e}")
|
|
|
|
# 输出总结
|
|
if files_with_bom:
|
|
print(f"\n发现{len(files_with_bom)}个文件含有BOM字符:")
|
|
for file in files_with_bom:
|
|
print(f"- {file}")
|
|
else:
|
|
print("\n所有检查的文件都不含有BOM字符。") |