JSI Tip 10465. How can I determine the local path of a mapped drive letter?

Jerold Schulman

May 3, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today


Using RMTShare.exe, I have scripted MapPath.bat to return a server's drive and folder path using a client's mapped drive letter.

The syntax for using MapPath.bat is:

[CALL] MapPath Drive: answer

Where:

Drive: is the mapped drive letter and colon.

answer is a call directed environment variable that will contain the the server's Drive and folder path, or NONE if Drive: cannot be located. If the folder path contains spaces, the answer string will be quoted.

Example:

Mapped   Share                     'server' drive and folder path                          AnswerDrive    X:     \Computer1Share1      c:test                                                 c:test    Y:     \Computer2Share2      C:Documents and SettingsJerryMy DocumentsMy Stuff   "C:Documents and SettingsJerryMy DocumentsMy Stuff"    Z:     \Compurer0NotFound    . . . . .                                               NONE

MapPath.bat contains:

@echo offsetlocalif {%2}=={} goto errset work=%1set work=%work:"=%set DRV=%work:~0,2%if "%DRV:~1,1%" NEQ ":" goto errset share=NONEset ans=Nfor /f "tokens=1,2*" %%a in ('net use %DRV%^|find "Remote"^|find "name"') do ( set share=%%c)if "%share%" EQU "NONE" goto finishfor /f "Tokens=1*" %%a in ('rmtshare %share%^|Findstr /b /c:"Path "') do ( set ans=%%b)set work=%ans: =%if "%work%" EQU "%ans%" goto finishset ans="%ans%":finishendlocal&set %2=%ans%goto :EOF:err@echo Syntax:  MapPath Drive: answer



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like