Batch file 批处理文件连接命令行参数

Batch file 批处理文件连接命令行参数,batch-file,Batch File,例如,我创建了一个名为concatenate.bat的批处理文件: @echo off set foo=%1\bar echo %foo% 当我运行concatenate.bat“C:\where\with spaces” 我希望foo输出: “C:\where\with spaces\bar” 但我得到的却是: “C:\某处\带空格”\bar 我也尝试过:set“foo=%1\bar” 其中输出:“C:\某处\带空格”\bar 正确的方法是什么?没问题,很高兴我能帮上忙:)请有人解释一下

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

@echo off
set foo=%1\bar
echo %foo%
当我运行
concatenate.bat“C:\where\with spaces”

我希望foo输出:
“C:\where\with spaces\bar”

但我得到的却是:
“C:\某处\带空格”\bar


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

其中输出:
“C:\某处\带空格”\bar



正确的方法是什么?

没问题,很高兴我能帮上忙:)请有人解释一下这个答案中的内容好吗?%1的解释可以在中找到。简言之,它展开%1以删除任何周围的引号。
@echo off
set foo="%~1\bar"
echo %foo%