title: find specific folder in any mapped drive and report its full UNC path
body: <p>I was wondering if it was possible using a batch file to find a specific folder in any mapped drive of a PC and have it report the folders full UNC path. Lets say a PC has drives mapped of N:\ &amp; S:\ (or any usual network drive letter for that matter). The folder could be in either folder and I run some code to find where the folder is, it will be in the root of the drive share (avoiding need for recursive subfolder scanning) e.g. N:\Special_Folder however, the end result of the code will report the FULL UNC e.g.</p>
  
  <p>Folder Found!..</p>
  
  <p>\server-vm01\data\shared_area\special_folder </p>
  
  <p>Hope that makes sense. I have tried with some code I already use to identify a USB stick, but am having difficulty porting it to the needs above. Any pointers would be great, thank you.</p>
  
  <pre><code>for %%a in (d: e: f: g: h: i: j: k: l: m: n: o: p: q: r: s: t: u: v: w: x: y: z:) do | find "special_folder" &gt;nul &amp;&amp; set unc=%%a:
  echo %unc%
  pause
  </code></pre>
  
  <p>edit for troubleshoot, output net use</p>
  
  <p>Microsoft Windows [Version 10.0.14393]
  (c) 2016 Microsoft Corporation. All rights reserved.</p>
  
  <p>C:\Users\Admin>net use
  New connections will be remembered.</p>
  
  <pre><code>Status       Local     Remote                    Network
  
  -------------------------------------------------------------------------------
  OK           Y:        \\DISKSTATION\NetBackup   Microsoft Windows Network
  OK           Z:        \\DISKSTATION\NetBackup   Microsoft Windows Network
  The command completed successfully.
  
  
  C:\Users\Admin&gt;
  </code></pre>
  
  <p>I tried to fix and I got as far as trying FOR /F "tokens=2-3 delims= " in the first line and that removes the Microsoft Windows Networ but then drops a letter out the path e.g \DISKSTATION\NetBacku\specialfolder</p>
  
  <p>also If I run as admin, as will need to, the code doesn't echo any path, does non admin ? Thanks</p>
  
  <p><strong><em>EDIT</em></strong> <strong>(final)</strong> </p>
  
  <p>Thank you both for these really helpful codes. I shall edit the original question with what works, both do as it happens, but I can only tick one solution by the looks of it. </p>
  
  <p>Test Environment:-</p>
  
  <p><strong>Win10 (UAC is ON)</strong></p>
  
  <p><strong>Win7 (UAC is off)</strong></p>
  
  <p>Two Mapped Drives in each with a test Folder called Daphne in root of just one of the 2 drives.</p>
  
  <pre><code>    @echo off
      FOR /F "skip=2 delims=" %%G IN ('"wmic logicaldisk where drivetype=4 get name,providername /format:csv"') do (
         FOR /F "tokens=2,3 delims=," %%H IN ("%%G") DO (
             IF EXIST "%%I\Daphne\" echo %%I\Daphne
          )
       )
  pause
  </code></pre>
  
  <p>The above works perfectly on the Win7 (UAC is off) test system, Admin or not. Works as non Admin Win10 (UAC is ON), <strong>doesn't</strong> work running as "Admin" though. </p>
  
  <p>Below <strong>worked everywhere</strong> regardless of admin or not, in both environments.</p>
  
  <p>The original code suggested works fine (FYI) but I just needed it to output the path with no quotations or additional texts, so I am just adding the authors generous efforts (tweaked slightly) to conclude the original question in line with my original intentions. </p>
  
  <pre><code>@ECHO OFF
  SETLOCAL EnableExtensions DisableDelayedExpansion
  
  set "_FolderToSearch=Daphne"                  
  for /F "delims=" %%D in ('reg query "HKCU\Network"') do (
    for /F "tokens=1,2,*" %%f in ('reg query "%%~D" /v RemotePath ^| find /I "RemotePath"') do (
      if exist "%%~h\%_FolderToSearch%\" echo %%~h\%_FolderToSearch%
    )
  )
  pause
  </code></pre>
  
  <p>Below is the output on the screen from both code snippets in their working forms:-</p>
  
  <pre><code>\\DISKSTATION\NetBackup\Daphne
  Press any key to continue . . .
  
  \\DISKSTATION\NetBackup\Daphne
  Press any key to continue . . .
  </code></pre>
  
  <p>I can now easily set this as a path statement in a config file to completely automate client software installations by having the customer just tell me the folder name of where they want our data on their network. I shall test first and report back. </p>
  
  <p>Thankyou! </p>