[Solved] Break Batch If/ELSE Statement into multiple lines – Hard to Read Code


Taking the initial code in the link, and adding parentheses helps to break down the If and Else structure:

@Echo Off
For %%Z In ("%ATTR%") Do (
    If "%%~aZ" GEq "d" (
        Echo Directory
    ) Else (
        If "%%~aZ" GEq "-" (
            Echo File
        ) Else (
            Echo Inaccessible
        )
    )
)
Pause

So to modify it with GoTo‘s, perhaps something like this is more suitable for your purposes:

@Echo Off
PushD "%~dp0"
ClS
Set "ATTR=%AppData%\Microsoft\Excel\XLSTART"
For %%Z In ("%ATTR%") Do (
    If "%%~aZ" GEq "d" (
        GoTo DIR
    ) Else (
        If "%%~aZ" GEq "-" (
            GoTo FILE
        ) Else (
            GoTo NOACCESS
        )
    )
)
GoTo NOTFOUND

:DIR
Echo "Directory Found!"
GoTo ENDFOR

:FILE
Echo "File Found!"
GoTo ENDFOR

:NOTFOUND
Echo "Not Found!"
GoTo ENDFOR

:NOACCESS
Echo "Inaccessible!"

:ENDFOR
Pause
Exit /B

0

solved Break Batch If/ELSE Statement into multiple lines – Hard to Read Code