Nested IF ( IF ( … ) ELSE( .. ) ) statement in batch

前端 未结 5 1131
春和景丽
春和景丽 2021-02-18 23:13

I\'m trying to write an IF ELSE statement nested inside another IF statement. Here\'s what I have:

IF %dirdive%==1 ( 
    IF DEFINED lo         


        
5条回答
  •  情深已故
    2021-02-18 23:50

    Change IF DEFINED log to: IF EXIST log. The following works for me:

    echo off
    set log=log.txt
    set /p dirdive= Enter a directory:
    IF %dirdive%==1 ( 
        IF EXIST %log% (
            ECHO "in IF" %DATE%, %TIME% >> %log%
            FOR /R %root1% %%G IN (.) DO (
                SET _G=%%G
                CALL :TESTEVERYTHING !_G:~0,-1! %root1% %root2% %log%
            )
            GOTO :end
        ) ELSE ( 
            ECHO "in ELSE" %DATE%, %TIME%
            FOR /R %root1% %%G IN (.) DO (
                SET _G=%%G
                CALL :TESTEVERYTHINGnolog !_G:~0,-1! %root1% %root2%
            )
            GOTO :end
        )
    )
    :end
    

提交回复
热议问题