Page 1 of 1

report UNC path of folder in a mapped

Posted: 05 Oct 2016 12:55
by technotika
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

Re: report UNC path of folder in a mapped

Posted: 05 Oct 2016 20:07
by Compo
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

Re: report UNC path of folder in a mapped

Posted: 05 Oct 2016 20:16
by Squashman
Looks similar to a question I just answered on SO today.

Re: report UNC path of folder in a mapped

Posted: 06 Oct 2016 15:15
by foxidrive
The person forget to update all the other forums the question was pasted to. :mrgreen: