Multiple commands in batch file loop

  • Thread starter Thread starter mrgou
  • Start date Start date
M

mrgou

Hi,

In a batch file, is it possible to execute more than one command for
each iteration of a FOR loop (i.e. more than one command for each file
of the set)?

Thanks!

mrgou
 
Create a secondary batch file that processes each file and call it like
this:

for %f in (*.txt) do call process.bat %f


=process.bat=
@Echo Off
Command1.exe %1
Command2.exe %1
etc...


HTH
 
Best to include the PowerShell equivalent: ;-)

gci *.txt | % {Command1.exe $_.FullName; Command2.exe $_.FullName}
 
Any relation to the DEC Gordon Bell?

--
BobF.
Gordon Bell said:
Best to include the PowerShell equivalent: ;-)

gci *.txt | % {Command1.exe $_.FullName; Command2.exe $_.FullName}
 
Hi,
this newsgroup is about powershell, not batch, but I'll answer anyway.
You don't need to use a separate batchfile, you can do that in the same
batch by using ( and ) like this:

For %%f in (*.txt) do (
Command1 %1
Command2 %1
)

Greetz,
Ben
 
Back
Top