mdMD Command – Create Directories in Windows Command Prompt
Learn how to use the MD command to create new directories in Windows CMD. MD is identical to MKDIR—both create folders. Complete guide with syntax, examples, and best practices.
The MD command (Make Directory) is a Windows Command Prompt utility that creates new directories (folders) at a specified location, automatically creating any intermediate parent directories in the path. MD is the shorthand for MKDIR—both work identically. Use MD to create single directories, nested folder structures with one command, or multiple directories in batch operations; the full name MKDIR provides the same functionality for those who prefer explicit command names.
Whether you're a system administrator setting up directory structures for new projects, a developer organizing source code repositories, or a power user managing file collections, MD provides reliable folder creation with automatic parent directory handling. IT professionals rely on MD for automated directory provisioning, project scaffolding, and standardized folder structure deployment across enterprise environments.
This comprehensive guide covers MD syntax, all parameters and options, practical examples for common directory creation scenarios, troubleshooting tips for creation failures, related directory management commands, and frequently asked questions. By the end, you'll confidently create directories and complex folder hierarchies from the command line for file organization, project setup, and system administration tasks.
What Is the MD Command?
The MD command is a fundamental file system tool in Windows Command Prompt that creates new directories. It can create single folders, entire directory trees with nested subdirectories in one command, and multiple directories simultaneously—all without requiring manual creation of intermediate parent folders.
MD works in Command Prompt (CMD), Windows PowerShell (with CMD compatibility), Windows Terminal, and is available in all Windows versions from MS-DOS through Windows 11, Windows Server 2022, and all enterprise editions. The command has a full-name variant MKDIR that functions identically, offering a more descriptive alternative for scripts and documentation.
The command's ability to automatically create intermediate directories sets it apart from many file management operations—you can create C:\Projects\Web\Frontend\Components even if Projects, Web, and Frontend don't exist yet. MD creates the entire path in one operation, making it invaluable for project initialization and automated directory provisioning.
MD vs MKDIR
- MD: Shorter; preferred for interactive use; saves typing
- MKDIR: Full name; preferred for scripts and documentation; self-documenting
Both commands are identical. Use MD for speed in interactive sessions, MKDIR for clarity in scripts.
Syntax
MD [drive:]path
MKDIR [drive:]path
Parameters
| Parameter | Description |
|---|---|
[drive:] | Specifies the drive where the directory should be created (optional) |
path | Specifies the name and location of the new directory (required) |
No additional parameters: MD has a simple syntax with no switches or options. Its power comes from automatic parent directory creation and support for full paths.
How to Use MD Command
Create a Single Directory
Create a new folder in the current directory:
MD newfolder
MD temp
The directory is created immediately in your current location.
Create Directory with Full Path
Specify the complete path to create a directory anywhere on your system:
MD C:\Projects\NewProject
MD D:\Backup\2026-02
Use absolute paths for clarity and reliability in scripts.
Create Nested Directories
MD automatically creates all intermediate directories in the path if they don't exist:
MD C:\Projects\Web\Frontend\Components
MD C:\Data\Logs\2026\February\Week1
If Projects, Web, and Frontend don't exist, MD creates them all, then creates Components. This is one of MD's most powerful features.
Create Directory in Parent Location
Use .. to create a directory in the parent folder:
MD ..\SiblingFolder
MD ..\..\GrandparentFolder
Useful for creating folders relative to your current location without typing full paths.
Create Multiple Directories
Create several directories by running multiple MD commands or chaining with &&:
MD folder1
MD folder2
MD folder3
Or chain them:
MD folder1 && MD folder2 && MD folder3
Create Directory on Different Drive
Specify the drive letter to create directories on other drives:
MD D:\Projects
MD E:\Backup\Important
MD works across all local drives and mapped network drives.
Create Directory with Spaces in Name
Enclose paths containing spaces in double quotes:
MD "My Documents"
MD "C:\Program Files\My Application"
Without quotes, Windows interprets each word as a separate argument.
Create Dated Directories
Use date variables in batch scripts for automated dated folder creation:
MD Backup-%DATE:~-4,4%-%DATE:~-10,2%-%DATE:~-7,2%
Creates folders like Backup-2026-03-14 for organized backups.
Create Project Structure
Build entire project directory trees with multiple MD commands:
MD C:\Projects\MyApp
MD C:\Projects\MyApp\src
MD C:\Projects\MyApp\tests
MD C:\Projects\MyApp\docs
MD C:\Projects\MyApp\build
Or use nested paths:
MD C:\Projects\MyApp\src\components\ui
MD C:\Projects\MyApp\src\utils\helpers
Common Use Cases
-
Create project directories – Use MD to set up folder structures for new software projects, web applications, or development environments.
-
Build nested folder hierarchies – Use MD with full paths to create entire directory trees in one command without manually creating each level.
-
Organize files – Use MD to create folders for sorting and categorizing files by type, date, project, or any organizational scheme.
-
Set up development environments – Use MD in scripts to create standard project structures (src, tests, docs, build) for consistent development workflows.
-
Create temporary directories – Use MD to make temp folders for processing, staging files, or isolating operations.
-
Batch folder creation – Use MD in batch files to automate directory setup for deployments, installations, or system provisioning.
-
Prepare backup locations – Use MD to create dated backup folders organized by year, month, or week for systematic backup workflows.
-
Organize downloads – Use MD to create folders for sorting downloaded files by type, source, or purpose.
-
Set up user directories – Use MD in user provisioning scripts to create standard folder structures for new user accounts.
-
Create archive structures – Use MD to build hierarchical archive folders organized by date, project, or category.
-
Prepare deployment directories – Use MD in deployment scripts to create target directories for application files, configurations, and logs.
-
Organize media collections – Use MD to create folder structures for photos, videos, or music organized by date, event, or artist.
Tips and Best Practices
-
Quote paths with spaces – Always enclose paths containing spaces in double quotes:
MD "My Documents\New Folder". Without quotes, Windows treats each word as a separate directory name. -
MD creates intermediate directories automatically – No need for multiple commands to create nested paths.
MD C:\A\B\C\Dcreates all four directories if none exist. -
Use relative paths for portability – Create directories relative to your current location for scripts that work across different systems or user accounts.
-
Check if directory exists before creating – In scripts, prevent errors with:
IF NOT EXIST folder MD folder. This avoids "directory already exists" errors. -
Combine with CD to create and navigate – Chain commands to create and enter directories:
MD newfolder && CD newfolder. Useful for quick project initialization. -
Use descriptive folder names – Choose clear, meaningful names that indicate folder purpose. Avoid cryptic abbreviations that confuse future users.
-
Avoid special characters in directory names – Don't use
< > : " | ? *in folder names—these are reserved characters in Windows. Use underscores or hyphens instead. -
Use MD for interactive work – The shorter MD saves typing in interactive sessions. Use MKDIR in scripts for clarity and self-documentation.
-
Create standard project structures – Develop standard folder templates for projects and use MD scripts to create them consistently.
-
Use environment variables – Create user-specific directories with
MD %USERPROFILE%\Documents\MyFolderfor portable scripts. -
Document directory purposes – After creating directories, add README files explaining their purpose and contents for team collaboration.
-
Use consistent naming conventions – Establish naming standards (CamelCase, snake_case, kebab-case) and apply them consistently across directory structures.
Troubleshooting Common Issues
"A subdirectory or file already exists" Error
Problem: MD displays "A subdirectory or file [name] already exists" and fails.
Cause: A directory or file with the specified name already exists at that location.
Solution: Check if the directory exists:
DIR parent_directory
Use a different name or delete the existing directory:
RMDIR existing_directory
MD new_directory
In scripts, check before creating:
IF NOT EXIST folder MD folder
Prevention: Use IF NOT EXIST in scripts to check before creating directories. Choose unique names or clean up old directories first.
"The system cannot find the path specified" Error
Problem: MD fails with "The system cannot find the path specified."
Cause: The drive doesn't exist, you're trying to create a directory on a non-existent drive, or there's a typo in the path.
Solution:
- Verify the drive exists:
DIR D:\ - Check for typos in the path
- Ensure the parent path is valid
- Use Tab completion to avoid path errors
Prevention: Verify drive letters and paths before running MD. Use DIR to confirm parent directories exist.
"Access is denied" Error
Problem: MD fails with "Access is denied" when creating a directory.
Cause: Insufficient permissions, parent directory is read-only, or you're trying to create in a protected location.
Solution:
- Run Command Prompt as Administrator for system directories
- Verify you have write permissions on the parent directory
- Check if the parent has read-only or system attributes
- Use
ICACLS parent_pathto view permissions
Prevention: Run CMD as Administrator when creating directories in system locations. Verify write permissions on parent paths.
"The filename, directory name, or volume label syntax is incorrect"
Problem: MD fails with syntax error.
Cause: Invalid characters in path, reserved names (CON, PRN, AUX), or malformed path.
Solution:
- Avoid reserved names: CON, PRN, AUX, NUL, COM1-9, LPT1-9
- Remove invalid characters:
< > : " | ? * - Enclose paths with spaces in double quotes
- Check for trailing spaces or hidden characters
Prevention: Use valid characters only. Avoid reserved names. Quote paths with spaces.
Related Commands
RMDIR / RD – Remove Directories
RMDIR (or RD) deletes directories and optionally their contents. Use when you need to remove folders created with MD.
Key difference from MD:
- MD creates directories
- RMDIR removes directories
Example:
MD temp
REM ... use temp folder ...
RD /S /Q temp
When to use: Cleanup after operations, removing project folders, disk space management.
CD / CHDIR – Change Directory
CD (or CHDIR) changes the current working directory. Use after MD to navigate into the newly created folder.
Example:
MD C:\Projects\NewApp
CD C:\Projects\NewApp
When to use: Create and enter directories in one workflow.
DIR – List Directory Contents
DIR lists files and subdirectories. Use after MD to verify the directory was created: MD folder && DIR.
When to use: Verifying directory creation, listing new folder contents.
XCOPY / ROBOCOPY – Copy with Directory Creation
XCOPY and ROBOCOPY can create directory structures while copying files. Use when you need to copy files and create destination structure.
When to use: Setting up directory structures with initial file content.
Frequently Asked Questions
What is the difference between MD and MKDIR?
There is no difference; MD and MKDIR are identical commands. MD is the shorthand (Make Directory), and MKDIR is the full name. Both accept the same syntax and parameters and produce identical results. Most users prefer MD for brevity in interactive sessions.
Does MD create parent directories automatically?
Yes. MD automatically creates all intermediate directories in the path if they don't exist. For example, MD C:\A\B\C\D creates A, B, C, and D if none exist. No need for multiple commands.
How do I create a directory with spaces in the name?
Enclose the path in double quotes: MD "My New Folder" or MD "C:\Program Files\My App". Without quotes, Windows treats each word as a separate directory name.
Can MD create multiple directories at once?
MD creates one directory per command, but you can chain: MD folder1 && MD folder2 && MD folder3. For nested paths, a single MD command creates the entire tree: MD C:\A\B\C creates all three levels.
How do I avoid "directory already exists" error?
Check before creating: IF NOT EXIST folder MD folder. This prevents the error when the directory already exists. Alternatively, use a different name or remove the existing directory first.
What characters are invalid in directory names?
Avoid: < > : " | ? * and reserved names (CON, PRN, AUX, NUL, COM1-9, LPT1-9). Use letters, numbers, underscores, hyphens, and spaces (with quotes).
Can MD create directories on network drives?
Yes. MD works with mapped network drives: MD Z:\Projects\NewFolder. For UNC paths, use the full path: MD \\server\share\folder. Ensure you have create permissions on the share.
How do I create a directory in the parent folder?
Use .. for parent: MD ..\SiblingFolder or MD ..\..\GrandparentFolder. This creates directories relative to your current location.
Why does MD fail with "Access is denied"?
This occurs when you lack write permissions on the parent directory, the location is protected, or you need Administrator privileges. Run Command Prompt as Administrator for system directories.
Can I use environment variables with MD?
Yes. MD supports environment variables: MD %USERPROFILE%\Documents\MyFolder, MD %TEMP%\mydir, or MD %APPDATA%\MyApp\config. Useful for user-specific paths in scripts.
How do I create dated directories in a batch file?
Use date variables: MD Backup-%DATE:~-4,4%-%DATE:~-10,2%-%DATE:~-7,2% creates Backup-2026-03-14. Adjust the substring positions for your date format.
Does MD work in PowerShell?
Yes. MD (and MKDIR) work in PowerShell through CMD compatibility. PowerShell also has New-Item -ItemType Directory for native directory creation with additional options.
Quick Reference Card
| Command | Purpose | Example Use Case |
|---|---|---|
MD folder | Create single directory | Quick folder creation |
MD C:\path\folder | Create with full path | Absolute location |
MD C:\A\B\C | Create nested directories | Project structure |
MD ..\sibling | Create in parent | Relative path |
MD "My Folder" | Create with spaces | Quote path |
MD folder && CD folder | Create and enter | One-step setup |
IF NOT EXIST x MD x | Create if not exists | Script safety |
Try MD Command Now
Ready to practice creating directories? Use our Windows Command Simulator to run MD commands in your browser without risk. No installation required—practice MD, nested directory creation, and path handling in a safe environment.
Explore the full Commands Reference for more Windows CMD utilities, including MKDIR (identical to MD), directory operations (RMDIR, CD), and file management commands.
Summary
The MD command is the essential Windows tool for creating directories from the command line. Use MD to create single folders, entire directory trees with nested paths in one command, or multiple directories in sequence. MD and MKDIR are identical—use MD for brevity, MKDIR for clarity in scripts.
Remember that MD automatically creates intermediate directories, so MD C:\Projects\Web\Frontend creates Projects, Web, and Frontend if they don't exist. Always quote paths with spaces and use IF NOT EXIST in scripts to prevent errors.
Master MD for system administration tasks like project scaffolding, directory provisioning, backup folder creation, and automated deployment setup. Understanding MD's automatic parent creation and path handling ensures efficient directory management in Windows environments.