Windows shell中的连接不起作用

时间:2015-09-11 12:44:47

标签: windows cmd

显然这个批处理文件应该返回作为参数给出的输入文件的串联,但它不起作用:

set files=
for %%i in (%1 %2 %3 %4 %5 %6 %7 %8) do (
    echo %%i
    set files=%files% %%i
)

echo "the file list is %files%"
用以下方式调用

mybatchfile.bat example1.txt example2.txt 

预期结果应为:

example1.txt
example2.txt
the file list is example1.txt example2.txt

但在最后一行只有" example2.txt"。任何想法???

1 个答案:

答案 0 :(得分:1)

您需要启用延迟变量扩展(请注意以下代码中的扩展!files!):

set files=
setlocal EnableDelayedExpansion
for %%i in (%1 %2 %3 %4 %5 %6 %7 %8) do (
    echo %%i
    set files=!files! %%i
)
endlocal & set files=%files%
echo "the file list is %files%"