subst - Assign a Folder to a Drive
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
| Element | Description |
|---|---|
<drive>: | The drive letter to assign (for example, X:) |
<path> | The local folder to assign as a virtual drive |
/d | Removes 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.
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
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
substproducesDrive already SUBSTed; the letter of a physical or network drive producesInvalid parameter. The target folder must also exist. - The target must be a local folder. UNC paths such as
\\server\shareare not accepted. Usenet useto 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
substinside that Command Prompt. - Before removing an assignment, it is safer to close any windows or applications that have the virtual drive open.
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).