Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating a Loading Bar in a Batch file

941 views
Skip to first unread message

Matthew

unread,
Dec 12, 2009, 6:34:28 AM12/12/09
to
Hi,

I am creating a loading bar to show some visual effects for mapping
drives (in another script).

Can someone please help me why i am having alot of *'s done and not
just 20 as I want it to be? I have to cancel the script running.

Many thanks for your help!

@ECHO off
:: Clear and TITLE variable
CLS
SET TITLE=Mapping Drives
ECHO.
ECHO ===================================================
ECHO Loading the Mapped Drives for which you have access
ECHO ===================================================

REM \\lgad1-lk\NETLOGON\WKIX32.EXE \\lgad1-lk\NETLOGON\map_drives.kx
ECHO HI!!!

PAUSE

:: Setting a small loading bar script - this is from where i have a
problem

SET load=
SET /A loadnum=0

:Loading
SET load=%load%*
ECHO ----------------------------------------
ECHO %load%
ECHO ----------------------------------------

REM PING localhost -n 2 >nul

SET /A loadnum+=1

ECHO %loadnum%

IF %loadnum% == 20 GOTO Done

GOTO Loading

:Done

:: Finished the loading script

ECHO ===================================================
ECHO Successfuly Loaded all your mapped drives!
ECHO Your mapped drives can be found under My Computer
ECHO Have a Good Day!
ECHO ===================================================

CD C:

ECHO.

EXIT

foxidrive

unread,
Dec 12, 2009, 7:03:19 AM12/12/09
to
On Sat, 12 Dec 2009 03:34:28 -0800 (PST), Matthew <mpu...@gmail.com> wrote:

>I am creating a loading bar to show some visual effects for mapping
>drives (in another script).
>
>Can someone please help me why i am having alot of *'s done and not
>just 20 as I want it to be? I have to cancel the script running.

Each time it uses ECHO it includes a trailing CR/LF pair but if you use the
SET /P technique below it will print in a single bar.


@echo off

start "" /min \\lgad1-lk\NETLOGON\WKIX32.EXE ...\map_drives.kx

SET load=
SET /A loadnum=0

:Loading
set /p "=*"<nul
PING -n 2 localhost >nul
SET /A loadnum+=1
IF not %loadnum% EQU 20 GOTO :loading
echo.
pause

Matthew

unread,
Dec 12, 2009, 10:59:52 AM12/12/09
to
Thanks alot ...

This is how it is at the moment:

@ECHO off
:: Clear and TITLE variable
CLS
SET TITLE=Mapping Drives
ECHO.
ECHO ===================================================
ECHO Loading the Mapped Drives for which you have access
ECHO ===================================================

START "" /MIN \\lgad1-lk\NETLOGON\WKIX32.EXE \\lgad1-lk\NETLOGON
\map_drives.kx


:: Setting a small loading bar script

SET load=
SET /A loadnum=0

:Loading
SET /P "=*"<nul
REM PING localhost -n 2 >nul

SET /A loadnum+=1

IF NOT %loadnum% == 20 GOTO :Loading

:: Finished the loading script

ECHO ===================================================
ECHO Successfuly Loaded all your mapped drives!
ECHO Your mapped drives can be found under My Computer
ECHO Have a Good Day!
ECHO ===================================================

CD C:

ECHO.

EXIT


But this is the result:

===================================================


Loading the Mapped Drives for which you have access

===================================================
fixme:exec:SHELL_execute flags ignored: 0x00000500
Application could not be started, or no application associated with
the specified file.
ShellExecuteEx failed: File not found [THIS ERROR I know about it ..
the file does not exist for the time being I am testing it on another
machine]

*"===================================================


Successfuly Loaded all your mapped drives!

Your mapped drives can be found under My Computer

Have a Good Day!
===================================================

Thanks alot for your help!

foxidrive

unread,
Dec 12, 2009, 2:28:23 PM12/12/09
to
On Sat, 12 Dec 2009 07:59:52 -0800 (PST), Matthew <mpu...@gmail.com> wrote:

>Thanks alot ...
>
>This is how it is at the moment:
>

>IF NOT %loadnum% == 20 GOTO :Loading

Note the difference.

>> IF not %loadnum% EQU 20 GOTO :loading

The spaces will affect your comparison.

Tim Meddick

unread,
Dec 12, 2009, 3:42:26 PM12/12/09
to
Wouldn't :

IF NOT %loadnum%]==20] GOTO :Loading

...have worked?

==

Cheers, Tim Meddick, Peckham, London. :-)

Todd Vargo

unread,
Dec 13, 2009, 12:52:00 AM12/13/09
to
Tim Meddick wrote:
> Wouldn't :
>
> IF NOT %loadnum%]==20] GOTO :Loading
>
> ...have worked?

Foxidrive's point was that OP inserted spaces around the == which broke the
command. The OPs code will work if the spaces are omitted.

IF NOT %loadnum%==20 GOTO :Loading

Foxidrive provided an alternate format which eliminates this common error.

IF not %loadnum% EQU 20 GOTO :loading

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Matthew

unread,
Dec 13, 2009, 4:48:09 AM12/13/09
to
Thanks alot guys!!

But the problem still exists:

*" Syntax error

This is my piece of code (changed as per your suggestions)

:: Setting a small loading bar script

SET load=
SET /A loadnum=0

:Loading
set /p "=*"<nul


REM PING localhost -n 2 >nul

SET /A loadnum+=1

IF NOT %loadnum% EQU 20 GOTO :Loading

:: Finished the loading script

Thanks a lot for your help!

foxidrive

unread,
Dec 13, 2009, 5:51:58 AM12/13/09
to
On Sun, 13 Dec 2009 01:48:09 -0800 (PST), Matthew <mpu...@gmail.com> wrote:

>Thanks alot guys!!
>
>But the problem still exists:
>
>*" Syntax error
>
>This is my piece of code (changed as per your suggestions)
>
>:: Setting a small loading bar script
>
>SET load=
>SET /A loadnum=0
>
>:Loading
>set /p "=*"<nul
>REM PING localhost -n 2 >nul
>
>SET /A loadnum+=1
>
>IF NOT %loadnum% EQU 20 GOTO :Loading
>
>:: Finished the loading script
>
>Thanks a lot for your help!

The same code works here


@echo off


SET load=
SET /A loadnum=0

:Loading
set /p "=*"<nul
REM PING localhost -n 2 >nul

SET /A loadnum+=1

IF NOT %loadnum% EQU 20 GOTO :Loading

pause

billious

unread,
Dec 13, 2009, 8:12:41 AM12/13/09
to

"foxidrive" <got...@woohoo.invalid> wrote in message
news:2kr7i518b4lu1v9mb...@4ax.com...

Hmm - yes, you'd think so.

But consider:


This demo developed using XP
It may work for NT4/2K

----- batch begins -------
[1]@echo off
[2]set load=
[3]set loadnum=0
[4]:loop
[5]set load=*%load%
[6]echo %loadnum% - %load%
[7]set /a loadnum+=1
[8]if %loadnum% == 20 goto done
[9]if %loadnum%==20 goto done2
[10]goto loop
[11]
[12]:done
[13]echo DONE - If statement has spaces
[14]goto :eof
[15]
[16]:done2
[17]echo DONE - NO SPACES in If statement
[18]goto :eof
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed

The label :eof is defined in NT+ to be end-of-file but MUST be expressed as
:eof

If the spaces were affecting the comparison, then the exit should occur
through DONE2, not DONE.

In XP at any rate, the exit is through DONE.

So - is the comparison actually done on [pseudocode]
lefthandside.asinteger =?= righthandside.asinteger
or trim(lefthandside) =?= trim(righthandside)
or perhaps the second if the first fails the conversion?

As an experiment, I modified [8] to
[8]if %loadnum% == 020 goto done

and found that the exit was changed to DONE2. I conclude that the .asinteger
idea is not a flier.

changing [8] to
[8]if %loadnum% == 20 goto done

where there are many spaces before the 20 - did not break the operation -
the many-spaces were interpreted as none.

I tried all combinations of 0 to many spaces both between the IF and the
first argument and before the GOTO and around the '==' so I'm forced to the
conclusion that the syntax is IF token1==token2 actionstatement

But that's XP/H. Perhaps it depends on target OS - but I'd be very sceptical
of the affected-by-spaces notion in this instance. Certainly more forgiving
than a SET statement...

Todd Vargo

unread,
Dec 13, 2009, 7:32:02 PM12/13/09
to
billious wrote:
> "foxidrive" <got...@woohoo.invalid> wrote in message
> news:2kr7i518b4lu1v9mb...@4ax.com...
> > On Sat, 12 Dec 2009 07:59:52 -0800 (PST), Matthew <mpu...@gmail.com>
> > wrote:
> >
> >>Thanks alot ...
> >>
> >>This is how it is at the moment:
> >>
> >>IF NOT %loadnum% == 20 GOTO :Loading
> >
> > Note the difference.
> >
> >>> IF not %loadnum% EQU 20 GOTO :loading
> >
> > The spaces will affect your comparison.
>
> Hmm - yes, you'd think so.
>
> But consider:
snip...

>
> I tried all combinations of 0 to many spaces both between the IF and the
> first argument and before the GOTO and around the '==' so I'm forced to
the
> conclusion that the syntax is IF token1==token2 actionstatement
>
> But that's XP/H. Perhaps it depends on target OS - but I'd be very
sceptical
> of the affected-by-spaces notion in this instance. Certainly more
forgiving
> than a SET statement...

Appears the addition of the EQU syntax permits use of spaces around the ==.
Works in win95cmd ported from W2K so I suspect it works for W2K too. Thanks
for bringing this to our attention billious.

foxidrive

unread,
Dec 14, 2009, 12:01:55 AM12/14/09
to
On Sun, 13 Dec 2009 21:12:41 +0800, "billious" <billio...@hotmail.com>
wrote:

>>>IF NOT %loadnum% == 20 GOTO :Loading
>>

>> The spaces will affect your comparison.
>
>Hmm - yes, you'd think so.
>
>But consider:

>changing [8] to


>[8]if %loadnum% == 20 goto done
>
>where there are many spaces before the 20 - did not break the operation -
>the many-spaces were interpreted as none.

Thanks billious. Spaces after %loadnum% didn't affect it either.

Matthew

unread,
Dec 14, 2009, 4:15:37 AM12/14/09
to
Thanks alot guys!

It did work now :) During the weekend I was testing this under WINE
since at home I have linux but now that I am at work and tested it
under the Windows environment it works excellent. Just for
completeness sake I am pasting the whole script now

Thanks

On Dec 14, 6:01 am, foxidrive <got...@woohoo.invalid> wrote:
> On Sun, 13 Dec 2009 21:12:41 +0800, "billious" <billious_1...@hotmail.com>

Matthew

unread,
Dec 14, 2009, 4:18:07 AM12/14/09
to
This is the script:

@ECHO off
:: Clear and TITLE variable
CLS

TITLE=A header for the batch file

:: Showing the welcome message


ECHO.
ECHO ===================================================
ECHO Loading the Mapped Drives

ECHO for which you have access
ECHO ===================================================
ECHO.
ECHO.

:: Do whatever you want as a command here
ECHO HI

:: Setting a small loading bar script

SET load=
SET /A loadnum=0

:Loading
set /p "=[X]"<nul
PING localhost -n 1 >nul

SET /A loadnum+=1

IF NOT %loadnum% EQU 17 GOTO :Loading

:: Finished the loading script
:: Showing the finished message
ECHO.
ECHO.
ECHO.


ECHO ===================================================
ECHO Successfuly Loaded all your mapped drives!
ECHO Your mapped drives can be found under My Computer
ECHO Have a Good Day!
ECHO ===================================================

:: Go back to c:\
C:


:: End the batch file
ECHO.

:: WAIT 5 seconds
PING localhost -n 5 >nul

:: Close and exit the window
EXIT

0 new messages