(E-Mail Removed) wrote:
> I bought a Airlink101 Office NAS ANAS350 with 500GB Seagate SATA drive
> in it for my home network to store files files like MP3's, pictures
> and to back up all my computers. I don't have domain server at my
> home. Everytime I reboot the NAS need me to remap the drives and
> sometimes it doesn't even take my password that I'd have to
> 'disconnect' all mapped drive and remap. It's kinda annoying. I
> started creating this batch file piece by piece based on someone else
> batch file to connect to my private folder as p: drive, s: drive as
> public drive and t: drive as the 160GB Seagate USB external drive.
>
> @echo off
> cls
> if exist p: goto drivefound2 else
> goto end
> :drivefound2
> net use p: /del
> :end
>
> pause
>
> if exist s: goto drivefound3
> goto end
> :drivefound3
> net use s: /del
> :end
>
> pause
>
> if exist t: goto drivefound4
> goto end
> :drivefound4
> net use t: /del
> :end
>
> pause
>
> net use p: \\airnas\default mypassword /user:airnas\default rem
> default as private folder
> net use s: \\airnas\public
> net use t: \\airnas\usb_disk\usb_c
>
> :END
> echo DONE!
>
> Is there anything more it can look better than this?
First of all, you can not have more than one label named "end". Well you
could, but only the first one will be seen by the GOTO statement. Second,
your 3 "IF EXIST" conditions only skip the GOTO statement that follows them.
If you reconstruct as "IF NOT EXIST" conditions, you could eliminate one
GOTO statement and one label each. The following code has a cleaner
appearance and IMO, is easier to follow program flow. Do you agree?
@echo off
cls
if not exist p: goto skip_p
net use p: /del
:skip_p
if not exist s: goto skip_s
net use s: /del
:skip_s
if not exist t: goto skip_t
net use t: /del
:skip_t
net use p: \\airnas\default mypassword /user:airnas\default
net use s: \\airnas\public
net use t: \\airnas\usb_disk\usb_c
echo DONE!
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)