Multiple commands in batch file loop

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
 
G

Gordon Bell

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
 
G

Gordon Bell

Best to include the PowerShell equivalent: ;-)

gci *.txt | % {Command1.exe $_.FullName; Command2.exe $_.FullName}
 
B

Bob F.

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}
 
Z

Zanten, Ben van

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
 

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