I referred to some material online and made an auto-exit countdown. The code is as follows:
@echo off
set t=5
set a=1
:EX
cls
color 2F
echo ---------------------------------------------
echo.
echo auto exit after %t% seconds......
echo.
echo ---------------------------------------------
call :ProcDelay EX0
:EX0
set /a t=%t%-%a%
if %t% GTR 0 goto EX
@exit
:ProcDelay delayMSec_
setlocal enableextensions
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set start_=%%h%%i%%j%%k
:_procwaitloop
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set now_=%%h%%i%%j%%k
set /a diff_=%now_%-%start_%
if %diff_% LSS 100 goto _procwaitloop
endlocal & goto %1
It works very well, it exits after 5 seconds, and it can count down too.
But I want to ask whether this code can be simplified?
Can the :EX0 part be simplified away? Having to use goto here is very troublesome.
And also this part inside it:
setlocal enableextensions
..................
endlocal
What are these markers for? Can someone explain?
@echo off
set t=5
set a=1
:EX
cls
color 2F
echo ---------------------------------------------
echo.
echo auto exit after %t% seconds......
echo.
echo ---------------------------------------------
call :ProcDelay EX0
:EX0
set /a t=%t%-%a%
if %t% GTR 0 goto EX
@exit
:ProcDelay delayMSec_
setlocal enableextensions
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set start_=%%h%%i%%j%%k
:_procwaitloop
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set now_=%%h%%i%%j%%k
set /a diff_=%now_%-%start_%
if %diff_% LSS 100 goto _procwaitloop
endlocal & goto %1
It works very well, it exits after 5 seconds, and it can count down too.
But I want to ask whether this code can be simplified?
Can the :EX0 part be simplified away? Having to use goto here is very troublesome.
And also this part inside it:
setlocal enableextensions
..................
endlocal
What are these markers for? Can someone explain?
