批处理文件串联命令行参数

And*_*ers 1 batch-file

例如,我创建了一个名为的批处理文件concatenate.bat

@echo off
set foo=%1\bar
echo %foo%
Run Code Online (Sandbox Code Playgroud)

当我跑步 concatenate.bat "C:\somewhere\with spaces"

我想要foo输出: "C:\somewhere\with spaces\bar"

但是我得到了: "C:\somewhere\with spaces"\bar


我也尝试过: set "foo=%1\bar"

哪个输出: "C:\somewhere\with spaces"\bar


正确的方法是什么?

Bal*_*i C 5

@echo off
set foo="%~1\bar"
echo %foo%
Run Code Online (Sandbox Code Playgroud)