You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求编写脚本:从嵌套子文件夹选图覆盖LauncherFolder对应图片

逐层选择Cosmetics资源并替换目标图片的Python脚本

这个脚本位于MainFolder目录下,会引导用户逐层选择Cosmetics内的Pack、Theme、Alternative(若存在),最终定位到Character/Launcher文件夹中的PNG图片,将其复制到PluginFolder/LauncherFolder目录下,替换原有的Chara.png或Launcher.png。

import os
import shutil

# 定义核心路径
LAUNCHER_FOLDER = os.path.join("PluginFolder", "LauncherFolder")
COSMETICS_ROOT = os.path.join(LAUNCHER_FOLDER, "Cosmetics")
TARGET_CHARA = os.path.join(LAUNCHER_FOLDER, "Chara.png")
TARGET_LAUNCHER = os.path.join(LAUNCHER_FOLDER, "Launcher.png")

def select_from_list(items, prompt):
    """显示列表让用户选择对应项,返回选中的路径或None"""
    if not items:
        print("没有可选内容,退出操作")
        return None
    
    print(f"\n{prompt}:")
    for idx, item in enumerate(items, 1):
        print(f"{idx}. {os.path.basename(item)}")
    
    while True:
        try:
            choice = int(input("请输入对应序号选择: "))
            if 1 <= choice <= len(items):
                return items[choice-1]
            else:
                print(f"请输入1到{len(items)}之间的有效序号")
        except ValueError:
            print("请输入有效的数字序号")

def main():
    # 检查Cosmetics目录是否存在
    if not os.path.isdir(COSMETICS_ROOT):
        print(f"错误: 未找到Cosmetics目录,路径为{COSMETICS_ROOT}")
        return
    
    # 选择Pack
    packs = [os.path.join(COSMETICS_ROOT, d) for d in os.listdir(COSMETICS_ROOT) if os.path.isdir(os.path.join(COSMETICS_ROOT, d))]
    selected_pack = select_from_list(packs, "请选择Pack")
    if not selected_pack:
        return
    
    # 选择Theme
    themes = [os.path.join(selected_pack, d) for d in os.listdir(selected_pack) if os.path.isdir(os.path.join(selected_pack, d))]
    selected_theme = select_from_list(themes, "请选择Theme")
    if not selected_theme:
        return
    
    # 检查是否有子目录(如Default/Alternative)
    sub_dirs = [os.path.join(selected_theme, d) for d in os.listdir(selected_theme) if os.path.isdir(os.path.join(selected_theme, d))]
    current_dir = selected_theme
    if sub_dirs:
        selected_sub = select_from_list(sub_dirs, "请选择子目录(如Default/Alternative)")
        if not selected_sub:
            return
        current_dir = selected_sub
    
    # 选择Character或Launcher文件夹
    target_folders = [os.path.join(current_dir, d) for d in os.listdir(current_dir) if os.path.isdir(os.path.join(current_dir, d)) and d in ("Character", "Launcher")]
    selected_folder = select_from_list(target_folders, "请选择Character或Launcher文件夹")
    if not selected_folder:
        return
    
    # 选择PNG图片
    png_files = [os.path.join(selected_folder, f) for f in os.listdir(selected_folder) if f.lower().endswith(".png")]
    selected_png = select_from_list(png_files, "请选择要使用的PNG图片")
    if not selected_png:
        return
    
    # 确定目标文件
    target_file = TARGET_CHARA if "Character" in selected_folder else TARGET_LAUNCHER
    target_name = "Chara.png" if "Character" in selected_folder else "Launcher.png"
    
    # 替换目标文件
    try:
        # 删除旧文件(如果存在)
        if os.path.exists(target_file):
            os.remove(target_file)
        # 复制并重命名新文件
        shutil.copy(selected_png, target_file)
        print(f"\n成功将{os.path.basename(selected_png)}替换为{target_name}")
    except Exception as e:
        print(f"替换文件时出错: {str(e)}")

if __name__ == "__main__":
    main()

使用说明

  • 将脚本保存为cosmetics_switcher.py放在MainFolder目录下
  • 运行脚本:打开终端/命令行,进入MainFolder,执行python cosmetics_switcher.py
  • 按照提示逐层输入序号选择对应的目录和图片即可

内容的提问来源于stack exchange,提问作者OtsukareSama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 11:42:20