Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
goodywp
- Posts: 265
- Joined: 31 Jul 2017 09:57
#1
Post
by goodywp » 18 Dec 2023 15:53
Hi all,
I got a struggle of this two if statement while I try to add another condition on the previous code.
Original code is as below:
Code: Select all
if defined RDL_TYPE_NAME (
call:UpCase RDL_TYPE_NAME
IF NOT "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:KIA=!" (
ECHO Skipping !RDL_TYPE_NAME!
set RDL_TYPE_NAME=
goto :endOfProcessing
) else (
call:ErrorPrompt "ERROR31: Download option is not available. Package creation failed ^!"
call:ClearBeforeBreak "error"
set /A ERRORC=31
goto :exit
)
)
Now I try to add another or if statement IF NOT "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:TKI=!"
as below
Code: Select all
if defined RDL_TYPE_NAME (
call:UpCase RDL_TYPE_NAME
IF NOT "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:KIA=!" or IF NOT "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:TKI=!" (
ECHO Skipping !RDL_TYPE_NAME!
set RDL_TYPE_NAME=
goto :endOfProcessing
) else (
call:ErrorPrompt "ERROR31: Download option is not available. Package creation failed ^!"
call:ClearBeforeBreak "error"
set /A ERRORC=31
goto :exit
)
)
I tried both or, | none is working frome above code
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 18 Dec 2023 18:46
When you read the help file for the IF command where did it show usage for using a PIPE or OR?
-
Aacini
- Expert
- Posts: 1913
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#3
Post
by Aacini » 18 Dec 2023 19:16
Your code is wrong, not because the way of write that condition, but because
the logic of such a condition. There are 3 possible results:
- The value of RDL_TYPE_NAME is equal to !RDL_TYPE_NAME:KIA=!, so is NOT equal to !RDL_TYPE_NAME:TKI=! and hence the IF is executed.
- The value of RDL_TYPE_NAME is equal to !RDL_TYPE_NAME:TKI=!, so is NOT equal to !RDL_TYPE_NAME:KIA=! and hence the IF is executed.
- The value of RDL_TYPE_NAME is not anyone of two values, so the IF is executed.
So, as you write your desired OR condition, don't matters the value of RDL_TYPE_NAME: the IF is
always executed...
Antonio
-
Batcher
- Posts: 74
- Joined: 16 Apr 2009 10:36
#4
Post
by Batcher » 18 Dec 2023 19:55
Code: Select all
if defined RDL_TYPE_NAME (
call :UpCase RDL_TYPE_NAME
if not "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:KIA=!" (
echo Skipping !RDL_TYPE_NAME!
set RDL_TYPE_NAME=
goto :endOfProcessing
) else if not "!RDL_TYPE_NAME!"=="!RDL_TYPE_NAME:TKI=!" (
echo Skipping !RDL_TYPE_NAME!
set RDL_TYPE_NAME=
goto :endOfProcessing
) else (
call :ErrorPrompt "ERROR31: Download option is not available. Package creation failed ^!"
call :ClearBeforeBreak "error"
set /a ERRORC=31
goto :exit
)
)