The %~dp0
will give exactly what you're asking for (i.e. \\server\share\to\folder
) . But you can't use it for your net use
command. The net use
command only accepts the \\server\share
part to create a drive-letter.
You can do some work to strip off the \to\folder
-part and add it later in your batch-files but it might be better to use the pushd \\server\share\to\folder
command. With that command there is a temporary driver-letter created and the current directory is automatically changed to the correct folder. With the popd
-command you're back where you started and the temporary drive is released.
So:
C:\> C:\>pushd \\wdmycloud\public\new folder Z:\New folder>::do your thing Z:\New folder> Z:\New folder>popd C:\>
B.T.W. if you need to find out what temporary drive is created you can use the %~d0
in your batch-files. And %~dp0
for the complete path, and so on (or %cd%
of course :)).