How can I exit a batch file from within a function?

前端 未结 4 480
自闭症患者
自闭症患者 2020-12-28 08:33

I have a simple function written to check for directories:

:direxist
if not exist %~1 (
    echo %~1 could not be found, check to make sure your location is          


        
4条回答
  •  一整个雨季
    2020-12-28 08:59

    Here's my solution that will support nested routines if all are checked for errorlevel I add the test for errolevel at all my calls (internal or external)

    @echo off
    call :error message&if errorlevel 1 exit /b %errorlevel%<
    @echo continuing
    exit /b 0
    :error
    @echo in %0
    @echo message: %1
    set yes=
    set /p yes=[no]^|yes to continue
    if /i "%yes%" == "yes" exit /b 0
    exit /b 1
    

提交回复
热议问题