T-581 AI生成打开图片文件夹

This commit is contained in:
chengma
2026-07-10 10:46:52 +08:00
parent 68afe34a8d
commit 87fcda47e7
5 changed files with 366 additions and 3 deletions
+36
View File
@@ -0,0 +1,36 @@
"""Helpers for opening local folders from the GUI."""
from __future__ import annotations
import os
import subprocess
import sys
def open_in_file_manager(path: str) -> str:
"""Open an existing directory with the platform file manager.
Returns the absolute path that was opened. The helper never creates
directories; callers should present FileNotFoundError as a user-facing
warning.
"""
target = os.path.abspath(str(path or ""))
if not os.path.isdir(target):
raise FileNotFoundError(f"目录不存在:{target}")
if sys.platform.startswith("win"):
startfile = getattr(os, "startfile", None)
if startfile is None:
raise OSError("当前系统不支持打开文件夹")
startfile(target)
return target
command = ["open", target] if sys.platform == "darwin" else ["xdg-open", target]
subprocess.Popen(
command,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
shell=False,
)
return target