Page 1 of 1

Brackets with If & For commands

Posted: 20 Jul 2008 22:52
by Tigers!
Is it possible to have multiple commands with the If & for command?
Does

Code: Select all

IF EXIST filename (
command 1
command 2
) ELSE (
command 1
command 2
command 3
)
work? Or is the format different? Can we do multiple commands with if?
Does

Code: Select all

FOR /D %variable IN (set) DO (
command 1
command 2
)
work? Or is the format wrong? Can we do multiple commands with for?

Posted: 21 Jul 2008 06:34
by greenfinch
Hi Tigers,

See http://technet2.microsoft.com/windowsse ... x?mfr=true

Generally use &&
"Use to run the command following && only if the command preceding the symbol is successful. Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully."

e.g.

Code: Select all

FOR /D %variable IN (set) DO (command 1 && command 2) 

Posted: 21 Jul 2008 17:22
by Tigers!
Thanks for that Greenfinch.
You obviously have far more success that I do in finding information on the Microsoft site!