3

Can I use windows command subst to map a drive & folder to another location?

I want to map say the temp folder

c:\foo\bar\temp

to

e:\buildserver\dev

I can easily map the temp directory to e: using

subst e: c:\foo\bar\temp

But how can I also add the path folding the drive \buildserver\dev

ojhawkins
  • 3,200
  • 15
  • 50
  • 67
  • What is meant to happen if something accesses `E:\buildserver` if you've managed to do this? – Damien_The_Unbeliever Dec 11 '13 at 07:10
  • 1
    The build server produces `.pdb` files that point to the server path which is `e:\buildserver\dev`. The copy of the code base on my local machine is at a different path `c:\foo\bar\dev` for example. So I need to create an `e:` drive with the folder names after pointing to my local drive `c:\foo\bar\dev`. Hope that makes sense @Damien_The_Unbeliever – ojhawkins Dec 11 '13 at 10:29
  • Note that `subst` is legacy technology. Avoid it if at all possible. – Harry Johnston Dec 11 '13 at 20:13

2 Answers2

3

You can create a directory junction like so:

mklink /J c:\foo\bar\temp\ e:\buildserver\dev\
CyberDude
  • 8,541
  • 5
  • 29
  • 47
-1

On Windows 10 and Windows 7, instead of subst e: c:\foo\bar\temp

NET USE E: "c:\foo\bar\temp"

This sticks across a reboot.

Kip Bryan
  • 461
  • 4
  • 6
  • This tells me `System error 67 has occurred. The network name cannot be found.` – this.myself May 27 '20 at 13:11
  • This is not correct. For one, this needs to use a network path (e.g. UNC path like `\\localhost\C$\foo`). Also, this is _not_ persistent across reboots. To make it persistent, use the `/PERSISTENT:YES` flag. However, the approach in general is not a good solution to the issue in the OP. Using a _junction_ as suggested by @CyberDude or a _symbolic directory link_ is preferable. For more information, see [“directory junction” vs “directory symbolic link”](https://superuser.com/questions/343074/directory-junction-vs-directory-symbolic-link). – lauxjpn Aug 29 '21 at 18:36