I have the following in a BAT file:
@echo off
Set /P _environment = Please Enter Environment [d] for Development or [a] for Acceptance:
IF ((%_environment% EQU "a") OR (%_environment% EQU "d"))
(goto sub_write_files)
ELSE
(goto end)
:sub_write_files
xcopy script_temp\* \\CHU-%_environment%101\CHU\scripts /D /E /C /R /I /K /Y /S
:end
echo %_environment% Done
The logic seems well formed to me, but possibly it is not because the sub_write_files sub routine every time that I fire this command. I am assuming that the flaw is in the conditional logic.
You need to brush up on your batch syntax. Help is available for just about every command by typing either
HELP commandorcommand /?at a command prompt. For example,HELP IFwill provide help on the IF command. Granted, the documentation is often incomplete and/or confusing, but it is a start.You have lots of problems with your syntax as written. One of the most obvious is IF does not support any operators like AND, OR, XOR etc.
You can achieve the logic you were looking for with the following
There are lots of potential improvements. For example, you might want to add the
/Ioption to both IF statements so that case does not matter. Or you might want to loop back and try again instead of ending if an invalid value is entered.