If conditionals - not working

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

If conditionals - not working

#1 Post by SIMMS7400 » 10 Jan 2018 13:01

Hi Folks -

This may be so simple I'm over looking things, but I'm having trouble with if logic using "IF DEFINED" syntax.

For instance, I would like for this to work:

Code: Select all

IF DEFINED ERR_FILE IF DEFINED FDMEE_ERR (
	SET "SW_ATTACH=%LOGFILE%|%ERR_FILE%|%INTRAPATH%%MONTHPOV%%YEARPOV%_%MAXFILE%"
	MOVE /Y "*.log" "%INTRAPATH%" >nul 2>&1
) ELSE IF NOT DEFINED ERR_FILE IF DEFINED FDMEE_ERR (
	SET "SW_ATTACH=%LOGFILE%|%INTRAPATH%%MONTHPOV%%YEARPOV%_%MAXFILE%"
) ELSE (
	SET "SW_ATTACH=%LOGFILE%"
)
But it does not, so therefore, I need to use this format:

Code: Select all

SET "SW_ATTACH=%LOGFILE%"

IF DEFINED ERR_FILE IF DEFINED FDMEE_ERR (
	SET "SW_ATTACH=%LOGFILE%|%ERR_FILE%|%INTRAPATH%%MONTHPOV%%YEARPOV%_%MAXFILE%"
	MOVE /Y "*.log" "%INTRAPATH%" >nul 2>&1
)
IF NOT DEFINED ERR_FILE IF DEFINED FDMEE_ERR (
	SET "SW_ATTACH=%LOGFILE%|%INTRAPATH%%MONTHPOV%%YEARPOV%_%MAXFILE%"
)
Can anyone explain why? Thanks!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: If conditionals - not working

#2 Post by aGerman » 10 Jan 2018 14:01

This is equivalent to your first code and should explain the behavior:

Code: Select all

IF DEFINED ERR_FILE (
  IF DEFINED FDMEE_ERR (
    SET "SW_ATTACH=%LOGFILE%|%ERR_FILE%|%INTRAPATH%%MONTHPOV%%YEARPOV%_%MAXFILE%"
    MOVE /Y "*.log" "%INTRAPATH%" >nul 2>&1
  ) ELSE (
    IF NOT DEFINED ERR_FILE (
      IF DEFINED FDMEE_ERR (
        SET "SW_ATTACH=%LOGFILE%|%INTRAPATH%%MONTHPOV%%YEARPOV%_%MAXFILE%"
      ) ELSE (
        SET "SW_ATTACH=%LOGFILE%"
      )
    )
  )
)
Steffen

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: If conditionals - not working

#3 Post by SIMMS7400 » 10 Jan 2018 14:27

Hi Steffan -

Thank you very much!

I'm following. Is there a better way to consutruct than option #2 I outlined above?

I"ll keep playing around with it - thanks again!

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: If conditionals - not working

#4 Post by penpen » 10 Jan 2018 16:36

You could check if FDMEE_ERR is defined first:

Code: Select all

SET "SW_ATTACH=%LOGFILE%"

IF DEFINED FDMEE_ERR IF DEFINED ERR_FILE (
	SET "SW_ATTACH=%LOGFILE%|%ERR_FILE%|%INTRAPATH%%MONTHPOV%%YEARPOV%_%MAXFILE%"
	MOVE /Y "*.log" "%INTRAPATH%" >nul 2>&1
) else (
	SET "SW_ATTACH=%LOGFILE%|%INTRAPATH%%MONTHPOV%%YEARPOV%_%MAXFILE%"
)
penpen

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: If conditionals - not working

#5 Post by SIMMS7400 » 11 Jan 2018 02:50

Thank you, all!

Post Reply