Jump to content

Count down in a batch file


Recommended Posts


hi

is it posible to have a visible Count down in a batch file

what i mean is this:

this window closes in 5 seconds, and it Counts down visible

:)

You again :P

With all those questions about batch file you had lately, you're going to raise your knowledge.

Don't forget search button and Google are your friend and reading others batches can help a lot either.

5 seconds countdown

@echo off
echo this window closes in 5 seconds
echo.
echo 5
ping -n 2 127.0.0.1>nul
echo 4
ping -n 2 127.0.0.1>nul
echo 3
ping -n 2 127.0.0.1>nul
echo 2
ping -n 2 127.0.0.1>nul
echo 1
ping -n 2 127.0.0.1>nul

pause

:)

Link to comment
Share on other sites

hi

is it posible to have a visible Count down in a batch file

what i mean is this:

this window closes in 5 seconds, and it Counts down visible

:)

You again :P

With all those questions about batch file you had lately, you're going to raise your knowledge.

Don't forget search button and Google are your friend and reading others batches can help a lot either.

5 seconds countdown

@echo off
echo this window closes in 5 seconds
echo.
echo 5
ping -n 2 127.0.0.1>nul
echo 4
ping -n 2 127.0.0.1>nul
echo 3
ping -n 2 127.0.0.1>nul
echo 2
ping -n 2 127.0.0.1>nul
echo 1
ping -n 2 127.0.0.1>nul

pause

:)

COOL jdoe i had only:

ping -n 5 127.0.0.1>nul

so i did know but not all

only i did not know that i can use it this way ;)

btw believe me i use googel and when i do not find it i ask here

Link to comment
Share on other sites

  • 2 weeks later...

I am not a coder but here what i worked out.

echo off
cls && mode con: Cols=55 Lines=5 && Color 9f && TITLE COUNTDOWN
> Rest1.vbs Echo Wscript.sleep 875 && SET R1=Start /w Rest1.vbs
CLS
ECHO. && Echo .5 && ECHO COUNTDOWN 5 >> Test.txt && %R1% && CLS && ECHO. && Echo ..4 && ECHO COUNTDOWN 4 >> Test.txt &&  %R1% && CLS
ECHO. && Echo ...3 && ECHO COUNTDOWN 3 >> Test.txt &&  %R1% && CLS && ECHO. && ECHO ....2 && ECHO COUNTDOWN 2 >> Test.txt &&  %R1%
CLS && ECHO. && ECHO .....1 && ECHO COUNTDOWN 1 >> Test.txt &&  %R1% && CLS && COLOR F2
ECHO. && ECHO  CONTINUE >> Test.txt
SET /P = CONTINUE
DEL REST1.VBS && Test.txt
DEL Test.txt

Link to comment
Share on other sites

I am not a coder but here what i worked out.

echo off
cls && mode con: Cols=55 Lines=5 && Color 9f && TITLE COUNTDOWN
> Rest1.vbs Echo Wscript.sleep 875 && SET R1=Start /w Rest1.vbs
CLS
ECHO. && Echo .5 && ECHO COUNTDOWN 5 >> Test.txt && %R1% && CLS && ECHO. && Echo ..4 && ECHO COUNTDOWN 4 >> Test.txt &&  %R1% && CLS
ECHO. && Echo ...3 && ECHO COUNTDOWN 3 >> Test.txt &&  %R1% && CLS && ECHO. && ECHO ....2 && ECHO COUNTDOWN 2 >> Test.txt &&  %R1%
CLS && ECHO. && ECHO .....1 && ECHO COUNTDOWN 1 >> Test.txt &&  %R1% && CLS && COLOR F2
ECHO. && ECHO  CONTINUE >> Test.txt
SET /P = CONTINUE
DEL REST1.VBS && Test.txt
DEL Test.txt

works nice i'l be useing yours then ;)

thanks

Link to comment
Share on other sites

  • 8 years later...

You may find the following fun!

@MODE CON: COLS=32 LINES=1
@COLOR E5
@TITLE Countdown
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /F %%# IN ('COPY /Z "%~dpf0" NUL') DO SET "CR=%%#"
FOR /L %%# IN (10,-1,1) DO (SET/P "=Script will end in %%# seconds. !CR!"<NUL:
PING -n 2 127.0.0.1 >NUL:)

The first three lines are pointless additions which can be removed, change the 10 in the second 'FOR loop' to the number of seconds you wish to count down from.

Link to comment
Share on other sites

On Windows 7 they have a exe called Timeout

Description:

This utility accepts a timeout parameter to w

time period (in seconds) or until any key is

accepts a parameter to ignore the key press.


Parameter List:
/T timeout Specifies the number of seconds to wait.
Valid range is -1 to 99999 seconds.

/NOBREAK Ignore key presses and wait specified time.

/? Displays this help message.

NOTE: A timeout value of -1 means to wait indefinitely for a key press.


Examples:
TIMEOUT /?
TIMEOUT /T 10
TIMEOUT /T 300 /NOBREAK
TIMEOUT /T -1

Link to comment
Share on other sites

  • 3 weeks later...

Here's a wait animation I wrote a while back, Only it's not based on a countdown:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET /A numtimes=3
FOR /L %%G in (1,1,%numtimes%) DO (
CALL :WaitDisplay "Please Wait"
)
CLS
ECHO Done! Press any key to finish...

PAUSE > NUL & GOTO :EOF

:WaitDisplay
SET string=%1
SET string=%string:"=%
SET dots=...

FOR /l %%G in (1,1,3) DO (
CLS
ECHO !string!!dots:~0,%%G!
PING localhost -n 2 -w 500 -l 5000 > NUL
)

Link to comment
Share on other sites

  • 4 months later...

Since this is a older thread and the original poster requested Cmd with countdown, I just recently wrote

this VBS script that has a countdown and you can cancel the countdown.


'-> Object For Runtime
Dim Act :Set Act = CreateObject("Wscript.Shell")
'-> Set The Amout Of Time For Count Down
Dim S1 :S1 = 15
Main()
Function Main()
If S1 = 0 Then
'-> Script Action For Time Out
MsgBox "Script Place Holder, Time Out",4128,"Demo CountDown"
WScript.Quit
End If
'-> add Zero EG 9 = 009
If Len(S1) = 1 Then S1 = "00" & S1
If Len(S1) = 2 Then S1 = "0" & S1
'-> Time Message Box
If Act.Popup( "Time Left : " & S1 & vbCrLf & _
"Press Cancel To Exit And Stop",1,"Test Count Down",4129) = 2 Then
MsgBox "User cancel",4128,"User Cancel"
WScript.Quit
End If
S1 = S1 - 1
Main()
End Function

Link to comment
Share on other sites

  • 3 months later...

Hi all,

I've just started using SyncToy to backup my data and I wanted it to be executed during the computer's log-out process. However, I also needed the option to cancel the sync process from running if, for example, it had already run earlier so I put together this little countdown batch script which seems to do the job nicely.

Essentially, when the script is invoked it gives you 10 seconds to press the "Y" button to cancel (during which time a running countdown is displayed) and after the 10 seconds have elapsed if you haven't pressed the "Y" button it will proceed to run the SyncToy process:-

@echo offset countdown=10:loopclschoice /C YN /n /t 1 /d N /M "Press Y to cancel sync. [%countdown%]"if %errorlevel%==1 (  echo Sync cancelled.  Logging off...  exit /B >nul)if %countdown% gtr 0 (  set /A countdown-=1  goto loop)echo Invoking SyncToy...CALL "C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -Rexit /B 0

Hopefully, this may prove useful to someone.

All the best,

Steve.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...