Concatenation in batch files

  • Thread starter Thread starter Robert Scheer
  • Start date Start date
R

Robert Scheer

Hi.

Maybe my question will be stupid, but I am trying to concatenate some
strings in a list without success. My batch file has a loop through all
the files of a folder:

FOR %%a in (C:\Images\*.jpg)

I need to create a variable that stores the returned filenames
separated by an space, this way:
Image1.jpg Image2.jpg Image3.jpg

After that I will pass this variable as an argument to an executable.

How can I do that kind of concatenation?

Thanks,
Robert Scheer
 
Robert said:
Hi.

Maybe my question will be stupid, but I am trying to concatenate some
strings in a list without success. My batch file has a loop through all
the files of a folder:

FOR %%a in (C:\Images\*.jpg)

I need to create a variable that stores the returned filenames
separated by an space, this way:
Image1.jpg Image2.jpg Image3.jpg

After that I will pass this variable as an argument to an executable.

How can I do that kind of concatenation?

This should do it


----------------------------
@echo off

pushd C:\Images

for /f "delims==" %%i in ('dir /b *.jpg') do call :Loop "%%i"

rem Note the quotes at end of previous line in case the filenames
rem have spaces in them.

goto :EchoResults

:Loop
Set FileList=%FileList% %1
GoTo :EOF

:EchoResults

echo %FileList%

popd
 
Back
Top