Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch check if mapped network drive exists

I'm currently writing a script that should map a network drive to the letter Z , i'm using the command net use z: \\path , the thing is that if the user is already using this letter i won't be able to map it, is there any way to check the existense of this drive (z) and if it exists to unmount it and mount it to a different letter and still use the z drive which i need for my script, this is a part of an installation, and it should be on Z drive.

like image 792
Alex Brodov Avatar asked Dec 02 '14 10:12

Alex Brodov


People also ask

How do I find my network drive in command prompt?

Use the MS-DOS "net share" command Click Start, Run, type cmd, and press Enter . At the MS-DOS prompt, type net share and press Enter . Each of the shares, the location of the resource, and any remarks for that share are displayed.


1 Answers

You can check whether the drive is mounted by IF EXIST Z:\. This should work:

if exist z:\ (     net use z: /delete ) net use z: \\path 
like image 51
MichaelS Avatar answered Sep 27 '22 19:09

MichaelS