Home All Groups Group Topic Archive Search About

Concatenation in batch files

Author
9 Feb 2006 2:05 PM
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

Author
9 Feb 2006 6:36 PM
Rob Stow
Robert Scheer wrote:
Show quoteHide quote
> 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
--------------------------

Note the use of