subst - Assign a Folder to a Drive

Maintained on
Table of Contents

The subst command assigns a folder to a drive letter, creating a virtual drive.

For example, you can treat C:\Projects\MyApp\src as drive X: and reach a deeply nested folder with a short path.

Basic Syntax of the subst Command

subst [<drive>: <path>]
subst <drive>: /d
ElementDescription
<drive>:The drive letter to assign (for example, X:)
<path>The local folder to assign as a virtual drive
/dRemoves the assignment

Run it with no arguments to list the current assignments.

Basic Usage

Assign a Folder to a Drive

subst X: C:\Projects\MyApp\src

No message is shown on success. After that, just switch to X: to work with the folder’s contents.

X:
dir

Check Assignments

Run subst with no arguments.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>subst
X:: => C:\Projects\MyApp\src
C:\users\user>

Remove an Assignment

subst X: /d

Only the assignment is removed. The original folder and its files are not deleted.

When to Use It

  • When paths are too long to type comfortably, or when a tool fails on long paths
  • When running older applications or scripts that hard-code a drive letter
  • When you want to open a working folder with a short path

Notes

Assignments disappear after a restart or sign-out

subst assignments are not persistent. They are removed when you sign out or restart. If you need one every time, put a batch file containing the subst command in the Startup folder (shell:startup), or register it as a Task Scheduler task that runs at logon and only when the user is logged on (a task that runs whether or not the user is logged on uses a different session, so you will not see the drive).

  • You cannot use a drive letter that is already in use. A letter already assigned with subst produces Drive already SUBSTed; the letter of a physical or network drive produces Invalid parameter. The target folder must also exist.
  • The target must be a local folder. UNC paths such as \\server\share are not accepted. Use net use to assign a network share.
  • Assignments are managed per signed-in user session. An elevated Command Prompt and a regular one use separate drive-letter lists, so they may not see each other’s assignments. If a tool that requires administrator rights needs the drive, run subst inside that Command Prompt.
  • Before removing an assignment, it is safer to close any windows or applications that have the virtual drive open.
Choosing between mklink, net use and subst

Use mklink to make a folder appear under another folder, net use to give a network share a drive letter, and subst to give a local folder a short drive letter.

Batch File Example

This example removes any existing assignment first so it does not fail when the drive is already assigned.

@echo off
subst X: /d >nul 2>&1
subst X: C:\Projects\MyApp\src

If the letter is unused, /d produces an error, but >nul 2>&1 discards the output, so it does no harm. However, if X: is a real drive, both /d and subst fail (and the subst error is shown).

Practice Questions

Practice Problem

Which command removes the folder assigned to X: as a virtual drive?

Choose one answer.

  1. subst X: /r
  2. subst X: /d
  3. del X:

Practice Problem

Which statement about a virtual drive created with subst is correct?

Choose one answer.

  1. The assignment is kept after a restart
  2. The assignment is removed on restart or sign-out
  3. A network share (UNC path) can be specified directly
#Command Prompt #Batch Files #subst #Command Line #Commands