36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import os
|
|
import re
|
|
import shutil
|
|
|
|
# ====== 配置 ======
|
|
input_dir = r"E:\Train\裁剪EM14新\EM 14 REJ" # 原始 XML 文件夹路径
|
|
output_dir = r"E:\Train\裁剪EM14新\xmlOutput" # 修改后 XML 文件输出路径
|
|
offset = 157 # 要裁掉的像素值
|
|
|
|
# 创建输出文件夹(如果不存在)
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
def process_xml(file_path, output_path, offset):
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
if "<width>1400</width>" in content:
|
|
new_width = 1400 - offset
|
|
new_content = content.replace("<width>1400</width>", f"<width>{new_width}</width>")
|
|
|
|
with open(output_path, 'w', encoding='utf-8') as f:
|
|
f.write(new_content)
|
|
|
|
print(f"✅ 修改并保存: {os.path.basename(file_path)} → 宽度 {new_width}")
|
|
else:
|
|
# 直接复制未修改的文件
|
|
shutil.copy(file_path, output_path)
|
|
print(f"↪ 保持原样: {os.path.basename(file_path)}")
|
|
|
|
|
|
for filename in os.listdir(input_dir):
|
|
if filename.lower().endswith(".xml"):
|
|
input_path = os.path.join(input_dir, filename)
|
|
output_path = os.path.join(output_dir, filename)
|
|
process_xml(input_path, output_path, offset)
|