Saved Bookmarks
| 1. |
Solve : Counter from 1 to 10 .. Help Please !!? |
|
Answer» Please I wanna make (secounds counter) before do command Exactly I want the bat file account 1;2;3;4;5;6;7;8;9;10 after that renew Ip with ipconfig /flushdns ipconfig /release ipconfig /renew ******************* Renew Ip is ready but I need counter before do it thanks This is a fairly simple problem! @echo off Ping localhost -n 10 -w 1000 > nul Ipconfig /flushdns Ipconfig /release Ipconfig /renew The ping command effectively waits 10 seconds before continuing with the script. Very thanks can you make it view in the back dos screen like this 1,2,3,4,5,6,7,8,9,10 thanks you again try this: @ECHO OFF ECHO 1 ping -n 1 -w 1000 1.1.1.1 > nul ECHO 2 ping -n 1 -w 1000 1.1.1.1 > nul ECHO 3 ping -n 1 -w 1000 1.1.1.1 > nul ECHO 4 ping -n 1 -w 1000 1.1.1.1 > nul ECHO 5 ping -n 1 -w 1000 1.1.1.1 > nul ECHO 6 ping -n 1 -w 1000 1.1.1.1 > nul ECHO 7 ping -n 1 -w 1000 1.1.1.1 > nul ECHO 8 ping -n 1 -w 1000 1.1.1.1 > nul ECHO 9 ping -n 1 -w 1000 1.1.1.1 > nul ECHO 10 ping -n 1 -w 1000 1.1.1.1 > nul Ipconfig /flushdns Ipconfig /release Ipconfig /renewthanks all foxs WORKS all the same: Code: [Select]@echo off set count=0 :Loop if %count% == 10 goto flush ping localhost -w 1 -n 2 >nul set /a count+=1 echo %count% goto loop :Flush Ipconfig /flushdns Ipconfig /release Ipconfig /renewBatchFileBasics, that script doesn't really live up to your name. Wbrost's script is extremely easy and straightforward. The OP asked for an extension of my script, and judging by the simplicity of the request (no offence) implied that the OP had little to no knowledge of batch scripting, so the simpler the script the better (just incase he wanted to modify it in some way). I root for BatchfileBasics I guess, because he sees the idea of doing something 10 times by writing (nearly) the same lines 10 times over, and moves up a gear, by showing how to do the same thing with a loop, whose operation is reasonably clear it seems to me. I mean, what is COMPLICATED about: if count equals a number go here if it doesn't, go there Furthermore, the loop can be edited more easily: to modify the number of counts you have to change just one number, not delete or add lines, (keeping track of the numbers!) With a little more experimentation one can make the loop count down from a maximum instead of up from a minimum, which has the advantage that during the count, the user can see just how many times more it is GOING to repeat. Just for interests sake, one could try this in the loop version instead of echo %count% (see what it does!) Code: [Select]0>nul set /p="%count% " or this in the inline version Code: [Select]0>nul set /p="1 " Code: [Select]0>nul set /p="2 " Code: [Select]0>nul set /p="3 " (etc) (The space before the SECOND quote is there for a reason) (put an echo. statement after showing the last number) Or... here are versions using FOR for anybody interested. No labels, no GOTO, no IF. Code: [Select]@echo off set FIRST=1 set step=1 set last=10 FOR /L %%N IN (%first%,%step%,%last%) DO ( echo %%N ping localhost -w 1 -n 2 >nul ) REM YOUR CODE HERE Code: [Select]@echo off set first=1 set step=1 set last=10 FOR /L %%N IN (%first%,%step%,%last%) DO ( 0>nul set /p="%%N " ping localhost -w 1 -n 2 >nul ) echo. REM YOUR CODE HERE Another idea is to put the changing count value in the window title, which may also be visible on the taskbar when the window is minimized. Code: [Select]TITLE %count% TITLE %%N TITLE 1 TITLE 2 TITLE 3 (etc) but you probably would like to change the title to something else after the countdown is over e.g. Code: [Select]TITLE C:\WINDOWS\system32\cmd.exeQuote from: Helpmeh on July 31, 2009, 02:56:59 PM BatchFileBasics, that script doesn't really live up to your name. Wbrost's script is extremely easy and straightforward.yes, easy and straightforward, BUT not flexible. if he wants to count to 100, is he going to write 100 echos and pings? using a loop is the most sensible thing to do. |
|