Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Count down in a batch file

- - - - -

  • Please log in to reply
17 replies to this topic

#1
sixpack

sixpack

    Senior Member

  • Member
  • PipPipPipPip
  • 515 posts
  • Joined 29-May 04
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
:)
Never say, "Oops!" always say, "Ah, interesting!"


How to remove advertisement from MSFN

#2
jdoe

jdoe

    Advanced Member

  • Member
  • PipPipPip
  • 314 posts
  • Joined 02-May 04

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


:)

#3
sixpack

sixpack

    Senior Member

  • Member
  • PipPipPipPip
  • 515 posts
  • Joined 29-May 04

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
Never say, "Oops!" always say, "Ah, interesting!"

#4
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,419 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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



GunSmokingMan



#5
sixpack

sixpack

    Senior Member

  • Member
  • PipPipPipPip
  • 515 posts
  • Joined 29-May 04

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
Never say, "Oops!" always say, "Ah, interesting!"

#6
DataCracker7899

DataCracker7899

    Newbie

  • Member
  • 15 posts
  • Joined 02-January 13
  • OS:Windows 7 x86
  • Country: Country Flag
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

Attached Files


Edited by DataCracker7899, 13 January 2013 - 05:08 AM.

I am a professional programmer and plz email me and i will help you. my email is: andregoodarzi@hotmail.com i'm master in many programming languages and i can make websites too.


//AndreG7899
//DataCracker7899

#7
FixitUP

FixitUP

    Newbie

  • Banned
  • 47 posts
  • Joined 17-November 12
  • OS:XP Pro x86
  • Country: Country Flag
Nice coding.

How would I get it to exit instead of continue ?

Thanks.

#8
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,543 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#9
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,419 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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



GunSmokingMan



#10
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,543 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

On Windows 7 they have a exe called Timeout

Just change the last line of my above example to read:
>NUL TIMEOUT /T 1)


#11
AceInfinity

AceInfinity

    Newbie

  • Member
  • 22 posts
  • Joined 10-August 11
  • OS:Windows 7 x64
  • Country: Country Flag
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
)

Microsoft MVP - .NET Programming (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


#12
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,419 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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



GunSmokingMan



#13
stevielamb

stevielamb
  • Member
  • 2 posts
  • Joined 26-October 13
  • OS:Windows 7 x86
  • Country: Country Flag

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 off

set countdown=10

:loop
cls

choice /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" -R
exit /B 0

Hopefully, this may prove useful to someone.

 

All the best,

 

 

 

Steve.



#14
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,580 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

@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



#15
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,543 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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

#16
stevielamb

stevielamb
  • Member
  • 2 posts
  • Joined 26-October 13
  • OS:Windows 7 x86
  • Country: Country Flag

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

@echo off
setlocal enableDelayedExpansion

FOR /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
)

:backup
echo Invoking SyncToy...
CALL "C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -R
exit /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.



#17
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,580 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

 

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.or...dos-choice.html

 

jaclaz



#18
AwesomeKing

AwesomeKing
  • Member
  • 1 posts
  • Joined 18-March 14
  • OS:Windows 8 x64
  • Country: Country Flag

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

@echo off
@title Freedom
@color 0b
set /a b=%a%-1
echo CountDown Time?
set /p a=

:loop
cls
set /a a=%a%-1
echo %a%
ping -n 2 127.0.0.1>nul
goto loop

This one closes after it runs out

@echo off
@title Freedom
@color 0b
set /a b=%a%-1
echo CountDown Time?
set /p a=

:loop
cls
set /a a=%a%-1
echo %a%
ping -n 2 127.0.0.1>nul
if %a%==0 goto finish
goto loop

:finish
echo  Complete. Now Exiting...
pause>nul
exit

Edited by Yzöwl, 19 March 2014 - 06:00 AM.
Code tags added...





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users