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

如何修改批处理脚本截取Haydee 2之后的文件路径

批处理脚本优化方案

以下是修改后的批处理脚本,可自动截取Haydee 2之后的子路径生成.sound文件:

@echo off
setlocal enabledelayedexpansion

REM Check if a file was dragged onto the script
if "%~1"=="" (
    echo Drag a file onto this script to create a .sound file.
    pause
    exit /b
)

REM Define the name and path of the dragged file
set "SourceFile=%~1"
set "FileName=%~n1"
set "FileExt=%~x1"
set "FullPath=%~dpnx1"

REM 提取Haydee 2之后的子路径
set "TargetPath=!FullPath:*Haydee 2\=!"

REM Generate the content for the .sound file
set "SoundFileContent=HD_DATA_TXT 300"
echo !SoundFileContent! > "!FileName!.sound"
echo. >> "!FileName!.sound"
echo soundCue >> "!FileName!.sound"
echo { >> "!FileName!.sound"
echo     sound "!TargetPath!"; >> "!FileName!.sound"
echo     range 128.0; >> "!FileName!.sound"
echo     volume 1.0; >> "!FileName!.sound"
echo } >> "!FileName!.sound"

echo .sound file has been successfully created.
echo The path has been automatically truncated to Haydee 2 subdirectory.
timeout /t 5
exit /b

关键修改说明

  • 新增路径截取逻辑:set "TargetPath=!FullPath:*Haydee 2\=!",利用批处理字符串替换特性,直接清除Haydee 2\之前的所有路径内容(包括盘符、Steam库路径),仅保留后续子路径
  • 重构文件写入方式:原脚本通过拼接长字符串写入的方式容易出现转义问题,改为逐行写入更稳定可靠
  • 更新提示信息:明确告知用户路径已自动完成截取,无需手动修改

修改后生成的.sound文件示例

HD_DATA_TXT 300 

soundCue 
{ 
    sound "Sounds\customMusic\example.wav";
    range 128.0; 
    volume 1.0; 
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 14:10:31