奇怪的替换是批处理文件中的无效错误

Weird substitution is invalid error in batch file

我最近一直在使用 for 语句从命令行执行大量批处理工作。今天,我决定将我正在使用的命令的一些大行捆绑到一个批处理文件中。主要问题是变量替换在某些情况下会给我带来奇怪的错误。那么有人可以向我解释一下这是如何工作的吗:

:: Split
for /F "tokens=*" %%F in ('dir /s /b *.cue') do (
pushd .
cd %%~dpF
mkdir out
cd out
echo "%%~dpF*.flac"
popd
)

还有这个:

:: Split
for /F "tokens=*" %%F in ('dir /s /b *.cue') do (
pushd .
cd %%~dpF
mkdir out
cd out
shntool.exe split -f "%%F" -t %t -m /-?; -o flac "%%~dpF*.flac"
popd
)

给我这个错误:

The following usage of the path operator in batch-parameter
substitution is invalid: %~dpF*.flac"

我建议

shntool.exe split -f "%%F" -t %t -m /-?; -o flac "%%~dpF*.flac"

被解释为

shntool.exe split -f "%%F" -t %~dpF*.flac"

因为 %t -m /-?; -o flac "% 将被视为环境变量。

使用

shntool.exe split -f "%%F" -t %%t -m /-?; -o flac "%%~dpF*.flac"