Concatenation in batch files

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
 
R

Rob Stow

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top