1

I have a batch file located in several folders and in this file I need to replace the old subst T: . command for net use because the units (drives) have different properties in windows 7.

However, I have only found that net use only allows for absolute paths such as:

net use T: \\path\to\folder

I cannot work with absolute paths, but net use T: . is not allowed (it throws an error).

Is there a way to execute the net use command from a folder so that it uses the current .bat directory?

I think the best solution for me it would be to be able to get the absolute qualified path (\path\to\folder) with a batch command. (%cd% and chdir variables do not work in this case). Questions about getting the current directory or folder name are not useful since the net usecommand does not allow paths such as x:\path\to\folder

Jorge
  • 121

1 Answers1

2

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 :)).

Rik
  • 13,565