report UNC path of folder in a mapped

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
technotika
Posts: 10
Joined: 02 Jun 2011 06:22

report UNC path of folder in a mapped

#1 Post by technotika » 05 Oct 2016 12:55

Hi All,

I am trying to put a batch together that searches through the mapped drives of PC, finds a specific folder, then reports back the full UNC of that folder.

A customer PC has say three mapped drives N:\ Y:\ S:\ I ask them before I visit to create a folder called "Folder_Work" in the root of their shared area.

When I run my installer package, I'd like some extra code to search "any mapped drive" for "Folder_Work" and report back the UNC of it.

For example:

*!Folder found!*

\\servername\shared_area\data\company-files\folder_work

then I can set that to do something else I need to do. I guess I need to output the shares from Net Use but not sure how to set that into the search routine?

Any tips would be welcome. Thanks

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: report UNC path of folder in a mapped

#2 Post by Compo » 05 Oct 2016 20:07

A couple of ideas for you, (both untested).
Using Net Use:

Code: Select all

@Echo Off
SetLocal
For /F "Tokens=2*" %%A In ('Net Use^|FindStr/BC:"OK"') Do (
   If Exist "%%A\Folder_Work\" (Set "MDL=%%A"&SET "_=%%B"
      For /F "Delims=?" %%C In ('Call Echo="%%_:  =?%%"') Do Set "UNC=%%C"))
Echo=%MDL% holds %UNC%\Folder_Work
>Nul Timeout -1
Exit/B
Using WMIC

Code: Select all

@Echo Off
SetLocal
For /F "UseBackQ Skip=1 Tokens=1*" %%A In (
   `WMIC LogicalDisk Where "DriveType='4'" Get DeviceID^,ProviderName`
) Do If Exist "%%A\Folder_Work\" (Set "MDL=%%A"
      For /F "Delims=" %%C In ("%%B") Do Set UNC=%%C)
Echo=%MDL% holds %UNC%\Folder_Work
>Nul Timeout -1
Exit/B

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: report UNC path of folder in a mapped

#3 Post by Squashman » 05 Oct 2016 20:16

Looks similar to a question I just answered on SO today.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: report UNC path of folder in a mapped

#4 Post by foxidrive » 06 Oct 2016 15:15

The person forget to update all the other forums the question was pasted to. :mrgreen:

Post Reply