Brackets with If & For commands

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Tigers!
Posts: 6
Joined: 01 Jul 2008 21:57
Location: Australia

Brackets with If & For commands

#1 Post by Tigers! » 20 Jul 2008 22:52

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?

greenfinch
Posts: 36
Joined: 17 Jul 2008 07:37

#2 Post by greenfinch » 21 Jul 2008 06:34

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) 

Tigers!
Posts: 6
Joined: 01 Jul 2008 21:57
Location: Australia

#3 Post by Tigers! » 21 Jul 2008 17:22

Thanks for that Greenfinch.
You obviously have far more success that I do in finding information on the Microsoft site!

Post Reply