Batch scripting question: Progress Indicator

225 pts.
Tags:
Batch
DOS
Scripting
Hello all, 
I write quite a few batch scripts and have never really come across how to display some sort of progress counter for the file. Is there a way to do this or does it depend on the type of script that I am running? 
 Thank you.


Software/Hardware used:
Windows 7 Professional 64-bit
ASKED: January 19, 2012  4:53 PM
UPDATED: February 28, 2012  11:24 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can try this code (found on www.dostips.com) which uses the DOS window title as a progress indicator -

@ECHO OFF
set “max=11″
call :initProgress %max% “Window Title: [PPP]”
for /l %%N in (1,1,%max%) do (
ping -n 2 -w 1 127.0.0.1>NUL
call:doProgress
)
GOTO:EOF

:initProgress max format — initialize an internal progress counter and display the progress in percent
:: — max [in] – progress counter maximum, equal to 100 percent
:: — format [in,opt] – title string formatter, default is ‘[P] completed.’
:$created 20060101 :$changed 20080327
:$source http://www.dostips.com
set /a “ProgressCnt=-1″
set /a “ProgressMax=%~1″
set “ProgressFormat=%~2″
if not defined ProgressFormat set “ProgressFormat=[PPPP]”
set “ProgressFormat=%ProgressFormat:[PPPP]=[P] completed.%”
call:doProgress
EXIT /b

:doProgress — display the next progress tick
:$created 20060101 :$changed 20080327
:$source http://www.dostips.com
set /a “ProgressCnt+=1″
SETLOCAL ENABLEDELAYEDEXPANSION
set /a “per100=100*ProgressCnt/ProgressMax”
set /a “per10=per100/10″
set /a “per10m=10-per100/10-1″
set “P=%per100%%%”
set “PP=”
for /l %%N in (0,1,%per10%) do call set “PP=%%PP%%*”
for /l %%N in (%per10%,1,9) do call set “PP=%%PP%% ”
set “PPP=”
for /l %%N in (0,1,%per10m%) do call set “PPP=%%PPP%%*”
set “ProgressFormat=%ProgressFormat:[P]=!P!%”
set “ProgressFormat=%ProgressFormat:[PP]=!PP!%”
set “ProgressFormat=%ProgressFormat:[PPP]=!PPP!%”
title %ProgressFormat%
EXIT /b

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following