CMD Simulator
File Managementmkdir

MKDIR Command – Create Directories in Windows Command Prompt

Learn how to use the MKDIR command to create new directories and nested folder structures in Windows CMD. Complete guide with syntax, examples, and best practices.

Rojan Acharya·
Share

The MKDIR 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. Use MKDIR to create single directories, nested folder structures with one command, or multiple directories in batch operations; the shorthand MD works identically—both provide instant folder creation for file organization and system administration.

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, MKDIR provides reliable folder creation with automatic parent directory handling. IT professionals rely on MKDIR for automated directory provisioning, project scaffolding, and standardized folder structure deployment across enterprise environments.

This comprehensive guide covers MKDIR 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 MKDIR Command?

The MKDIR 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.

MKDIR 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 an alias MD that functions identically, offering a shorter alternative for frequent use.

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. MKDIR creates the entire path in one operation, making it invaluable for project initialization and automated directory provisioning.

MKDIR vs Manual Folder Creation

  • MKDIR: Command-line creation; scriptable; creates parent directories automatically; fast for multiple folders
  • Windows Explorer: GUI creation; manual; requires creating each parent directory separately; visual feedback
  • PowerShell New-Item: PowerShell-native; more verbose; additional options for permissions and properties

Use MKDIR for command-line workflows, scripts, and automated directory creation. Use Explorer for visual organization and one-off folder creation.

Syntax

MKDIR [drive:]path
MD [drive:]path

Parameters

ParameterDescription
[drive:]Specifies the drive where the directory should be created (optional)
pathSpecifies the name and location of the new directory (required)

No additional parameters: MKDIR has a simple syntax with no switches or options. Its power comes from automatic parent directory creation and support for full paths.

MKDIR vs MD: Both commands are identical. MD is simply a shorter alias for MKDIR. Most users prefer MD for brevity in interactive sessions, but MKDIR is clearer in scripts and documentation.

How to Use MKDIR Command

Create a Single Directory

Create a new folder in the current directory:

MKDIR 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:

MKDIR C:\Projects\NewProject
MD D:\Backup\2026-02

Use absolute paths for clarity and reliability in scripts.

Create Nested Directories

MKDIR automatically creates all intermediate directories in the path if they don't exist:

MKDIR C:\Projects\Web\Frontend\Components
MD C:\Data\Logs\2026\February\Week1

If Projects, Web, and Frontend don't exist, MKDIR creates them all, then creates Components. This is one of MKDIR's most powerful features.

Create Directory in Parent Location

Use .. to create a directory in the parent folder:

MKDIR ..\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 MKDIR commands or chaining with &&:

MKDIR folder1
MKDIR folder2
MKDIR folder3

Or chain them:

MKDIR folder1 && MKDIR folder2 && MKDIR folder3

Use MD Shorthand

The MD command is identical to MKDIR and saves typing:

MD temp
MD C:\Projects\NewApp

Most experienced users prefer MD for interactive work due to its brevity.

Create Directory on Different Drive

Specify the drive letter to create directories on other drives:

MKDIR D:\Projects
MD E:\Backup\Important

MKDIR works across all local drives and mapped network drives.

Create Directory with Spaces in Name

Enclose paths containing spaces in double quotes:

MKDIR "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:

MKDIR Backup-%DATE:~-4,4%-%DATE:~-10,2%-%DATE:~-7,2%

Creates folders like Backup-2026-02-13 for organized backups.

Create Project Structure

Build entire project directory trees with multiple MKDIR commands:

MKDIR C:\Projects\MyApp
MKDIR C:\Projects\MyApp\src
MKDIR C:\Projects\MyApp\tests
MKDIR C:\Projects\MyApp\docs
MKDIR C:\Projects\MyApp\build

Or use nested paths:

MKDIR C:\Projects\MyApp\src\components\ui
MKDIR C:\Projects\MyApp\src\utils\helpers

Common Use Cases

  1. Create project directories – Use MKDIR to set up folder structures for new software projects, web applications, or development environments.

  2. Build nested folder hierarchies – Use MKDIR with full paths to create entire directory trees in one command without manually creating each level.

  3. Organize files – Use MKDIR to create folders for sorting and categorizing files by type, date, project, or any organizational scheme.

  4. Set up development environments – Use MKDIR in scripts to create standard project structures (src, tests, docs, build) for consistent development workflows.

  5. Create temporary directories – Use MKDIR to make temp folders for processing, staging files, or isolating operations.

  6. Batch folder creation – Use MKDIR in batch files to automate directory setup for deployments, installations, or system provisioning.

  7. Prepare backup locations – Use MKDIR to create dated backup folders organized by year, month, or week for systematic backup workflows.

  8. Organize downloads – Use MKDIR to create folders for sorting downloaded files by type, source, or purpose.

  9. Set up user directories – Use MKDIR in user provisioning scripts to create standard folder structures for new user accounts.

  10. Create archive structures – Use MKDIR to build hierarchical archive folders organized by date, project, or category.

  11. Prepare deployment directories – Use MKDIR in deployment scripts to create target directories for application files, configurations, and logs.

  12. Organize media collections – Use MKDIR to create folder structures for photos, videos, or music organized by date, event, or artist.

Tips and Best Practices

  1. Quote paths with spaces – Always enclose paths containing spaces in double quotes: MKDIR "My Documents\New Folder". Without quotes, Windows treats each word as a separate directory name.

  2. MKDIR creates intermediate directories automatically – No need for multiple commands to create nested paths. MKDIR C:\A\B\C\D creates all four directories if none exist.

  3. Use relative paths for portability – Create directories relative to your current location for scripts that work across different systems or user accounts.

  4. Check if directory exists before creating – In scripts, prevent errors with: IF NOT EXIST folder MKDIR folder. This avoids "directory already exists" errors.

  5. Combine with CD to create and navigate – Chain commands to create and enter directories: MKDIR newfolder && CD newfolder. Useful for quick project initialization.

  6. Use descriptive folder names – Choose clear, meaningful names that indicate folder purpose. Avoid cryptic abbreviations that confuse future users.

  7. Avoid special characters in directory names – Don't use < > : " | ? * in folder names—these are reserved characters in Windows. Use underscores or hyphens instead.

  8. Use MD for interactive work – The shorter MD alias saves typing in interactive sessions. Use MKDIR in scripts for clarity and self-documentation.

  9. Create standard project structures – Develop standard folder templates for projects and use MKDIR scripts to create them consistently.

  10. Use environment variables – Create user-specific directories with MKDIR %USERPROFILE%\Documents\MyFolder for portable scripts.

  11. Document directory purposes – After creating directories, add README files explaining their purpose and contents for team collaboration.

  12. 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: MKDIR 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
MKDIR new_directory

In scripts, check before creating:

IF NOT EXIST folder MKDIR 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: MKDIR 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 network drives are connected: NET USE
  • For network paths, verify server accessibility: PING server

Prevention: Verify drives and parent paths exist before running MKDIR. Use Tab completion to avoid typos.

"Access is denied" Error

Problem: MKDIR fails with "Access is denied" when trying to create directories.

Cause: Insufficient permissions to create directories in the target location, or the location is protected by Windows.

Solution:

  • Run Command Prompt as Administrator for system locations
  • Verify you have write permissions: ICACLS parent_directory
  • Choose a location where you have write access
  • For network shares, ensure you have create permissions

Prevention: Run CMD as Administrator when creating directories in system locations like Program Files or Windows directories.

MKDIR Creates Directory in Wrong Location

Problem: MKDIR creates the directory in an unexpected location.

Cause: Using relative paths without verifying current directory, or misunderstanding path resolution.

Solution: Check current directory:

CD

Use absolute paths for clarity:

MKDIR C:\Projects\NewFolder

Or navigate first:

CD C:\Projects
MKDIR NewFolder

Prevention: Use absolute paths in scripts for reliability. Always verify current directory with CD before using relative paths.

Cannot Create Directory with Long Path

Problem: MKDIR fails when creating directories with very long paths (>260 characters).

Cause: Windows has a 260-character path length limit (MAX_PATH) by default.

Solution:

  • Shorten directory names
  • Create directories closer to the root
  • Enable long path support in Windows 10/11: Group Policy or Registry edit
  • Use UNC paths with \\?\ prefix for paths >260 characters

Prevention: Keep directory structures shallow and use concise names. Enable long path support in Windows 10/11 for modern applications.

MKDIR Doesn't Work on Network Paths

Problem: MKDIR fails when trying to create directories on network shares.

Cause: Network share is inaccessible, you lack permissions, or the UNC path is incorrect.

Solution:

  • Verify network connectivity: PING server
  • Check if share is accessible: NET VIEW \\server
  • Verify permissions on the network share
  • Map the network drive first: NET USE Z: \\server\share
  • Then create directory: MKDIR Z:\newfolder

Prevention: Verify network connectivity and permissions before attempting to create directories on network shares.

Related Commands

CD – Change Directory

CD changes the current working directory. Use before MKDIR to navigate to the location where you want to create directories.

Example:

CD C:\Projects
MKDIR NewApp

Integration: Navigate with CD, then create directories with MKDIR in the target location.

RMDIR / RD – Remove Directories

RMDIR (or RD) deletes directories. Use to remove directories created by MKDIR.

Example:

RMDIR empty_folder
RMDIR /S /Q folder_with_contents

When to use: Cleaning up test directories, removing old project folders, or undoing MKDIR operations.

DIR – List Directory Contents

DIR displays directory contents. Use after MKDIR to verify directory creation.

Example:

MKDIR newfolder
DIR

Integration: Verify MKDIR success by listing directories with DIR.

TREE – Display Directory Structure

TREE shows a graphical tree of directory structure. Use after MKDIR to visualize created folder hierarchies.

Example:

MKDIR C:\Projects\App\src\components
TREE C:\Projects\App

When to use: Visualizing complex directory structures created with MKDIR.

XCOPY – Copy Directory Trees

XCOPY copies files and directory structures. Use to replicate directory structures created with MKDIR.

Example:

MKDIR C:\Template\src\components
XCOPY C:\Template D:\NewProject /E /I

Integration: Create template structures with MKDIR, then replicate with XCOPY.

ROBOCOPY – Robust Directory Operations

ROBOCOPY performs robust file and directory operations. Use for enterprise-grade directory creation and synchronization.

Example:

ROBOCOPY C:\Template D:\NewProject /E /CREATE

The /CREATE parameter creates directory structures without copying files.

When to use: Enterprise directory provisioning, template replication, or large-scale folder structure deployment.

Frequently Asked Questions

What does MKDIR do if the directory already exists?

MKDIR displays an error message: "A subdirectory or file [name] already exists." The command fails and does not overwrite or modify the existing directory. Use IF NOT EXIST in scripts to check before creating: IF NOT EXIST folder MKDIR folder.

How do I create multiple nested directories at once?

Simply specify the full path with all subdirectories: MKDIR C:\Parent\Child\Grandchild. MKDIR automatically creates all intermediate directories (Parent, Child) if they don't exist, then creates the final directory (Grandchild). This is one of MKDIR's most powerful features.

What is the difference between MKDIR and MD?

There is no difference; MKDIR and MD are identical commands. MD is simply a shorter alias for MKDIR. Both accept the same syntax and produce the same results. Most users prefer MD for brevity in interactive sessions, but MKDIR is clearer in scripts and documentation.

Can MKDIR create directories on network drives?

Yes, MKDIR works with UNC network paths and mapped network drives. Use MKDIR \\server\share\newfolder for UNC paths or MKDIR Z:\newfolder for mapped drives, provided you have write permissions. Verify network connectivity and permissions before creating directories on network shares.

How do I create a directory with spaces in the name?

Enclose the path in double quotes: MKDIR "My New Folder" or MKDIR "C:\Program Files\My App". Without quotes, Windows interprets each word as a separate argument and tries to create multiple directories. Always quote paths with spaces.

Can I create hidden directories with MKDIR?

MKDIR creates normal directories. To make a directory hidden, create it first with MKDIR, then use ATTRIB +H foldername to set the hidden attribute. Example: MKDIR secret && ATTRIB +H secret.

How do I create directories in batch scripts?

Use MKDIR or MD in batch files just like in interactive CMD. Add error checking with IF NOT EXIST:

@echo off
IF NOT EXIST C:\Projects MKDIR C:\Projects
IF NOT EXIST C:\Projects\App MKDIR C:\Projects\App

Or create nested paths directly:

MKDIR C:\Projects\App\src\components

Can MKDIR create directories on different drives?

Yes, specify the drive letter in the path: MKDIR D:\Projects or MD E:\Backup\2026. MKDIR works across all local drives and mapped network drives. Ensure the target drive exists and you have write permissions.

What happens if I use MKDIR without specifying a path?

MKDIR requires a path argument. Running MKDIR without arguments displays an error: "The syntax of the command is incorrect." Always specify at least a directory name: MKDIR foldername.

How do I create a directory in the parent folder?

Use .. to reference the parent directory: MKDIR ..\SiblingFolder. This creates a folder in the parent of your current directory. Use ..\.. to go up two levels: MKDIR ..\..\GrandparentFolder.

Can I use environment variables with MKDIR?

Yes, MKDIR supports environment variables: MKDIR %USERPROFILE%\Documents\MyFolder or MKDIR %TEMP%\ProcessingFolder. This creates user-specific or system-specific directories that work across different accounts and systems.

How do I create dated backup folders?

Use date variables in batch scripts:

@echo off
SET today=%DATE:~-4,4%-%DATE:~-10,2%-%DATE:~-7,2%
MKDIR C:\Backups\%today%

This creates folders like C:\Backups\2026-02-13 for organized backups.

Quick Reference Card

CommandPurposeExample Use Case
MKDIR folderCreate directoryMake new folder
MD folderCreate directory (short)Quick folder creation
MKDIR C:\path\folderCreate with full pathSpecific location
MKDIR A\B\CCreate nested directoriesBuild directory tree
MKDIR "My Folder"Create with spacesFolder names with spaces
IF NOT EXIST folder MD folderConditional creationPrevent errors in scripts
MKDIR folder && CD folderCreate and navigateQuick project start
MKDIR %USERPROFILE%\folderUse variablesUser-specific folders
MKDIR ..\siblingCreate in parentRelative path creation
MD D:\folderCreate on different driveCross-drive creation

Try MKDIR Command Now

Ready to practice creating directories? Use our Windows Command Simulator to run MKDIR commands safely in your browser. No installation required—practice MKDIR, nested directory creation, and project structure setup in a risk-free environment. Perfect for learning, training, or testing command sequences before running them on production systems.

Explore the full Commands Reference for more Windows CMD utilities, including file management (COPY, MOVE, DEL), directory operations (RMDIR, CD, DIR), and system administration commands.

Summary

The MKDIR command is the essential Windows tool for creating directories from the command line. Use MKDIR or its alias MD to create single folders, nested directory structures with automatic parent creation, or multiple directories in batch operations.

MKDIR automatically creates intermediate directories, making it simple to build complex folder hierarchies with a single command: MKDIR C:\A\B\C\D creates all four directories if none exist. This powerful feature eliminates the need for manual parent directory creation and streamlines project initialization.

Master MKDIR for project setup, file organization, backup structure creation, and automated directory provisioning. Understanding MKDIR is fundamental to command-line file management in Windows, enabling efficient folder creation for development, system administration, and file organization tasks.