Check if label exists cmd

前端 未结 5 821
深忆病人
深忆病人 2021-01-03 06:29

I wonder is there any way to check that if a label exist in a batch file?

If %input%=ABC (  
  If Label ABC Exists (
    Goto ABC
  )
)

How

5条回答
  •  抹茶落季
    2021-01-03 06:37

    If you add this to the top of your function:

    if "%~1" == "test" goto:eof

    You can use this to check if your function exists:

    call :myFunction test 2>nul

    if %errorlevel% == 0 call :myFunction

    Example:

    call :myFunction test 2>nul
    if "%errorlevel%" == "0" (call :myFunction) else (echo function does not exist)
    goto:eof
    
    :myFunction
        if "%~1" == "test" goto:eof
        echo Function exists
    goto:eof
    

提交回复
热议问题