Page 1 of 1
batch variable progress bar string manipulation
Posted: 21 Jun 2013 12:05
by tsip
Here's my code (i tried to make a progress bar but failed):
@echo off & setlocal enabledelayedexpansion
set bar=**********
set cnt=0
:LOOP
cls
set /A cnt+=1
echo.Progress:!bar:~0,%cnt%!
ping -n 1
www.google.com > nul 2>&1
if "%cnt%" NEQ 10 goto :LOOP
echo.finished.
pause > nul
exit /b
I get this as output: bar:~0,1 bar:~0,2 bar:~0,3 etc.. etc.. I want it to go like:*, **, *** etc.. basically increase the asterisk by 1 every second.
Re: batch variable progress bar string manipulation
Posted: 21 Jun 2013 12:48
by foxidrive
Code: Select all
@echo off
for /L %%a in (1,1,10) do (
set /p =*<nul
ping localhost -n 2 >nul
)
pause
Re: batch variable progress bar string manipulation
Posted: 21 Jun 2013 12:49
by aGerman
I see the same and for whatever reason the dot in
echo. is the key for that behaviour.
BTW
Never use
echo. - it has a lot of disadvantages. Better use
echo( even if it looks odd and you don't really need it in your code.
Code: Select all
@echo off & setlocal enabledelayedexpansion
set bar=**********
set cnt=0
:LOOP
cls
set /A cnt+=1
echo(Progress:!bar:~0,%cnt%!
ping -n 2 localhost >nul
if %cnt% NEQ 10 goto :LOOP
echo(finished.
pause >nul
As you can see I did some minor changes. But one thing is important: Never use double quotes for numeric comparisons.
Regards
aGerman
Re: batch variable progress bar string manipulation
Posted: 22 Jun 2013 02:21
by Endoro
the OP did some cross postings
here and
here
Re: batch variable progress bar string manipulation
Posted: 22 Jun 2013 18:25
by Ocalabob
@OP,
Some advice. Your calling Endoro a name ("copy cat") on another forum may curtail further help on your failed
attempt at a batch script on this forum. I suggest you refrain from such snarky comments when asking for help.
Your welcome!