0

apparently this batch file should return the concatenation of the input files given as arguments, but it is not working:

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%"

when invoked with:

mybatchfile.bat example1.txt example2.txt 

the expected result should be:

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

but in the final line only has "example2.txt". Any idea???

Raul Luna
  • 1,945
  • 1
  • 17
  • 26

1 Answers1

1

You need to enable delayed variable expansion (note the expansion !files! in the following code):

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%"
aschipfl
  • 33,626
  • 12
  • 54
  • 99