Friday, 2 October 2009

Simple Batch Progress Bar

Example 1. Print the bar within the window with '#' as the default filling character
call :progressbar 50
Example 2. The same as above but with an another filling character
call :progressbar 50 *
Example 3. Print the bar in the window title
set progressbar_t=1
call :progressbar 50
rem Prints the simple progress bar within the DOS window or in the window title
rem @usage   call :progressbar INTEGER [ STRING ]
rem @param   INTEGER The length of the progress bar
rem @param   STRING  Optional non-empty value defines the another filling character

set progressbar_c=%~2
if not defined progressbar_c (
    set progressbar_c=#
) else (
    set progressbar_c=%progressbar_c:~0,1%

set progressbar_s=
set /a progressbar_i=%~1

set progressbar_s=%progressbar_s%%progressbar_c%

if not defined progressbar_t (
    echo %progressbar_s%
) else (
    title %progressbar_s%

ping localhost -n 1 >nul

set /a progressbar_i-=1
if %progressbar_i% gtr 0 goto progressbar_1

goto :EOF

No comments:

Post a Comment