sixpack

Count down in a batch file

18 posts in this topic

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

:)

0

Share this post


Link to post
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

:)

0

Share this post


Link to post
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

0

Share this post


Link to post
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

0

Share this post


Link to post
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

0

Share this post


Link to post
Share on other sites

Download the scripts from my page. There is no viruses,malware ,spyware or anything harmful.

it's a ZIP file that has 2 files in it One is Executable and other one batch.

DOWNLOAD HERE: HERE!

or from below!

/.G7NANOZ_ANDRE7899 :thumbup

G7 NANOSCRIPTZ - ZIP.zip

Edited by DataCracker7899
0

Share this post


Link to post
Share on other sites

Nice coding.

How would I get it to exit instead of continue ?

Thanks.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
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

0

Share this post


Link to post
Share on other sites

On Windows 7 they have a exe called Timeout

Just change the last line of my above example to read:

	>NUL TIMEOUT /T 1)

0

Share this post


Link to post
Share on other sites

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
)

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

@Steve

Thanks, though at first sight I am failing to see why you are not using a FOR /L loop. :unsure:

Also, how long does the message:

Sync cancelled.  Logging off...

stay visible on screen? :unsure:

jaclaz

0

Share this post


Link to post
Share on other sites

…also please be aware that choice is not available by default in all OS's.

0

Share this post


Link to post
Share on other sites

I had actually forgotten that the "for loop" existed in windows batch scripts! Anyway, here's a revised version of the script:-

@echo offsetlocal enableDelayedExpansionFOR /l %%s in (10, -1, 0) DO (  cls  choice /C YNX /n /t 1 /d X /M "Invoking SyncToy in %%s seconds, press Y to cancel or N to proceed anyway."  if !errorlevel!==1 (    echo Sync cancelled.  Logging off...   exit /B  )  if !errorlevel!==2 goto backup):backupecho Invoking SyncToy...CALL "C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -Rexit /B 0

In reply to your other question, the "Sync cancelled. Logging off..." message remains on the screen just long enough to read it before the dos window shuts.

Thanks for your response.

Steve.

0

Share this post


Link to post
Share on other sites

In reply to your other question, the "Sync cancelled. Logging off..." message remains on the screen just long enough to read it before the dos window shuts.

Hmmm, you must be a speed reader or have a slowish machine. :ph34r:

Seriously :), inserting some kind of loop/delay between the echo and the exit command may be not a totally absurd idea.

For the record:

http://ss64.com/nt/choice.html

Choice.exe is a standard command in Windows 2003, Vista and Windows 7 (for XP you can use the early resource kit versions).

so, anyone with XP (or earlier) may have issues with it's use.

If an external something is needed/wanted, the choice.exe from FreeDOS should work on those:

http://winsupport.org/utilities/freedos-choice.html

jaclaz

0

Share this post


Link to post
Share on other sites

Here is a code i made that can countdown from any number.

@echo off@title Freedom@color 0bset /a b=%a%-1echo CountDown Time?set /p a=:loopclsset /a a=%a%-1echo %a%ping -n 2 127.0.0.1>nulgoto loop

This one closes after it runs out

@echo off@title Freedom@color 0bset /a b=%a%-1echo CountDown Time?set /p a=:loopclsset /a a=%a%-1echo %a%ping -n 2 127.0.0.1>nulif %a%==0 goto finishgoto loop:finishecho  Complete. Now Exiting...pause>nulexit
Edited by Yzöwl
Code tags added...
0

Share this post


Link to post
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.