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.
batch variable progress bar string manipulation
Moderator: DosItHelp
Re: batch variable progress bar string manipulation
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
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.
As you can see I did some minor changes. But one thing is important: Never use double quotes for numeric comparisons.
Regards
aGerman
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
@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!
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!