It's quite an old question but.. I was looking for the exact same answer as I was trying to create a batch that will use the UNC path to the actual location of the patch and do some things there (so only copy&paste to another location/folder and start again).
As I couldn't find an answer I found a solution myself, but it's not very beautiful and certainly not a simple command. But it's possible to implement in batch. On CMD it would be:
FOR /F "tokens=2" %i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
SET cNetworkPath=%i)
SET cNetworkPath=%cNetworkPath%%CD:~2%
ECHO %cNetworkPath%
You can copy the four lines (better 4+empty line) and paste them into CMD to get an imidiate echo of the path to copy it.
In batch you would use it a bit differently:
FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%~d0"') DO (
bNetworkPath=%%i)
SET bCheckPath=!bOriginalPath!%~p0
The variable %CD% stores the current path and you need only the drive letter so you only search for that with the FIND command in NET USE. With the "tokens=2" (or 3, depending on NET USE output) the %i variable stores the path to the drive letter you searched for. After that the second SET command adds the folders you browsed on the network drive with %CD:~2% (offset 2 to cut off the drive letter).
For batch you use the %~d0 or %~p0 variables. %0 stores the full path of the batch itself (e. g. Z:\temp\test.bat ; %~d0 = Z: ; %~p0 = \temp\ ; d = drive, p = path, f = full path, n = name) otherwise it's similar to the CMD command.
What about drives which are not currently connected (e.g., over a VPN which is currently disconnected)? – None – 2015-08-11T16:59:40.877
Thanks, do you know a way to get the full path of the current working directory? – Ofiris – 2013-05-27T11:23:32.630
1What about
echo %cd%
? – Endoro – 2013-05-27T14:53:34.217@Endoro,
echo %cd%
outputs the current directory (Z:\ABC
) and not\\netDrive\ABC
– Ofiris – 2013-05-30T07:59:10.030I don't think there is a simple command line you can do to get it. You may be able to write a batch / powershell script to do it, but I haven't tried to make one. Check the answer from Icarus on: http://superuser.com/questions/244579/copy-unc-network-path-not-drive-letter-for-paths-on-mapped-drives-from-windows?rq=1 maybe you can use it to your need.
– Darius – 2013-06-06T19:20:32.627