fix: 修复输出路径问题 — 路径解析改为基于应用目录而非CWD
当从外部目录(如D:\ccc)拖入文件时,输出文件会错误地写入源目录。 根因是所有路径使用相对路径 + os.getcwd() 解析,CWD不同则路径错误。 修复方案: - ConfigManager.get_path() 改为使用 app_root (exe所在目录/脚本所在目录) - 将 22 处裸硬编码 "data/result"/"data/output" 替换为 config.get_path() - 添加 result_folder 到默认配置和 config.ini - 修复 error_utils.py 中的路径匹配字符串 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -154,7 +154,7 @@ class OCRService:
|
||||
# 获取文件名(不含扩展名)
|
||||
base_name = os.path.splitext(os.path.basename(image_path))[0]
|
||||
# 生成Excel文件路径
|
||||
output_dir = self.config.get('Paths', 'output_folder', fallback='data/output')
|
||||
output_dir = self.config.get_path('Paths', 'output_folder', fallback='data/output', create=True) if hasattr(self.config, 'get_path') else os.path.abspath('data/output')
|
||||
excel_path = os.path.join(output_dir, f"{base_name}.xlsx")
|
||||
return excel_path
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ class TobaccoService:
|
||||
"""
|
||||
self.config = config
|
||||
# 修复配置获取方式,使用fallback机制
|
||||
self.output_dir = config.get('Paths', 'output_folder', fallback='data/output')
|
||||
self.output_dir = config.get_path('Paths', 'output_folder', fallback='data/output', create=True) if hasattr(config, 'get_path') else os.path.abspath('data/output')
|
||||
self.template_file = config.get('Paths', 'template_file', fallback='templates/银豹-采购单模板.xls')
|
||||
# 将烟草订单保存到result目录
|
||||
result_dir = "data/result"
|
||||
result_dir = config.get_path('Paths', 'result_folder', fallback='data/result', create=True) if hasattr(config, 'get_path') else os.path.abspath('data/result')
|
||||
os.makedirs(result_dir, exist_ok=True)
|
||||
self.output_file = os.path.join(result_dir, '银豹采购单_烟草公司.xls')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user