For /f loop with Progress Bar

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

For /f loop with Progress Bar

Post by MigrationUser »

20 Jun 2016 15:21
StenioF


Hello everyone, I would like to support to improve a batch script.
My script is basically a loop-FOR as below and would like to add a progress bar.
I researched a lot about progress bars, but basically all use a loop-FOR in the other and my script is use For-loop Too. I do not know how to put my loop within the progress bar examples

Note: Sorry for my english
following examples

-------------------------------------------

Code: Select all

@ECHO OFF
FOR /F "TOKENS=*" %%F IN (Patchs.TXT) DO DISM /online /add-package /packagepath:%%F /quiet /norestart
eCHO finished
PAUSE >NUL
---------------------------------------------

Would like add only status bar in my script
Bar Progress

Thank you in advance

Stenio L

----------------------------

#2 21 Jun 2016 09:59
bluesxman


Re: For /f loop with Progress Bar

How about a running total? That's nice and easy to implement:

Code: Select all

@ECHO OFF
set total=0
set count=0
FOR /F "TOKENS=*" %%F IN (Patchs.TXT) DO set /a total+=1
FOR /F "TOKENS=*" %%F IN (Patchs.TXT) DO call :install "%%~F"
ECHO Finished
PAUSE >NUL

goto :EOF

:install
set /a count+=1
cls
echo:Installing package [%count%/%total%]
DISM /online /add-package /packagepath:%1 /quiet /norestart

goto :EOF
Last edited by bluesxman (21 Jun 2016 10:33)

cmd | *sh | ruby | chef

----------------------------

#3 21 Jun 2016 14:43
bluesxman


Tweaked to add a percentage and a rough looking bar:

Code: Select all

@ECHO OFF
set total=0
set count=0

set  "bar_perc=0%%  10%%  20%%  30%%  40%%  50%%  60%%  70%%  80%%  90%%  100%%"
set "bar_scale=|....|....|....|....|....|....|....|....|....|....|"

FOR /F "TOKENS=*" %%F IN (Patchs.TXT) DO set /a total+=1
FOR /F "TOKENS=*" %%F IN (Patchs.TXT) DO call :install "%%~F"
ECHO Finished
PAUSE >NUL

goto :EOF

:install
set /a count+=1
set /a perc=( count * 100 ) / total
set /a perc.bar=1 + (( count * 50 ) / total)
cls
echo:Installing package [%count%/%total%] %perc%%%
echo:
set /p "out=%bar_perc%" < nul & echo:
call set /p "out=%%bar_scale:~0,%perc.bar%%%" <nul & echo:
echo:

DISM /online /add-package /packagepath:%1 /quiet /norestart

goto :EOF
Last edited by bluesxman (21 Jun 2016 14:53)

cmd | *sh | ruby | chef

----------------------------

#4 21 Jun 2016 20:28
StenioF


Thank a lot.
You are the man.

your script is good and functional.

att
Stenio L

----------------------------

#5 21 Jun 2016 22:17
bluesxman


No problem.

cmd | *sh | ruby | chef
Post Reply