cmd mkdir Command


The mkdir command in the Windows Command Prompt (cmd) is used to create new directories (folders). It stands for "make directory" and is a straightforward command that allows users to organize files by creating new folders.

Basic Syntax

mkdir [directory_name]

Key Points

  • You can create a single directory or multiple directories at once.
  • You can specify the full path to create a directory in a specific location.
  • If the specified directory already exists, mkdir will return an error message indicating that the directory already exists.

Examples of Using mkdir

Example 1: Create a Single Directory

To create a new directory named Projects in the current directory:

mkdir Projects

Output:

C:\Users\YourUsername>mkdir Projects

This command creates a new folder called Projects within the current directory.

Example 2: Create Multiple Directories

You can create multiple directories at once by listing them separated by spaces. For instance, to create directories named Photos, Documents, and Music:

mkdir Photos Documents Music

Output:

C:\Users\YourUsername>mkdir Photos Documents Music

This command creates three new folders named Photos, Documents, and Music in the current directory.

Example 3: Create a Directory with a Full Path

If you want to create a directory in a specific location, you can provide the full path. For example, to create a Work directory inside C:\Users\YourUsername\Documents:

mkdir C:\Users\YourUsername\Documents\Work

Output:

C:\Users\YourUsername>mkdir C:\Users\YourUsername\Documents\Work

This command creates a new folder named Work in the specified path.

Example 4: Create a Nested Directory

You can also create nested directories (subdirectories) in one command. For example, to create a directory structure like C:\Users\YourUsername\Projects\2024:

mkdir C:\Users\YourUsername\Projects\2024

Output:

C:\Users\YourUsername>mkdir C:\Users\YourUsername\Projects\2024

This command creates the 2024 folder inside the Projects folder. If the Projects folder does not exist, you'll need to create it first unless you use the /p option.

Using the /p Option

If you want to create nested directories and ensure that all parent directories are created as well, you can use the /p option. For example:

mkdir C:\Users\YourUsername\Projects\2024\NewProject

If Projects or 2024 does not exist, the command will fail unless you add /p:

mkdir /p C:\Users\YourUsername\Projects\2024\NewProject

Output:

C:\Users\YourUsername>mkdir /p C:\Users\YourUsername\Projects\2024\NewProject

This command will create the entire directory structure, including Projects and 2024, if they don't already exist.

Summary

The mkdir command is a powerful and essential tool in the Windows Command Prompt for creating directories. Whether you are organizing files, creating project folders, or establishing complex directory structures, mastering the mkdir command can greatly enhance your efficiency in file management.