Create a New Folder

Maintained on
Table of Contents

Creating the same folder structure over and over, or making numbered folders one by one by hand, is tedious.

This page shows how to create folders with the mkdir command. The same syntax works in both Command Prompt and batch files.

Command to Use

Use the mkdir command to create a folder. The abbreviated form md does the same thing.

mkdir <folder name>

There are no options; you only give the folder name as an argument. It is worth learning alongside its counterpart, the rmdir command.

Tip

If the folder name contains spaces, wrap it in double quotes, as in mkdir "my folder". Without quotes, separate folders are created for each space-separated word.

Executing from Command Prompt

This example creates a folder named “disposable” in the current directory. Right after Command Prompt starts, the current directory is your user folder (C:\Users\username); if opened as administrator, it is C:\Windows\System32.

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

Executing from a Batch File

@echo off
setlocal

set FOLDER=%userprofile%\Documents\
set NAME=disposable

mkdir "%FOLDER%%NAME%"

endlocal
exit /b

If a folder with the same name already exists, you get the error “A subdirectory or file already exists.” To avoid it, check with if not exist before creating the folder.

Create
if not exist "%FOLDER%%NAME%" mkdir "%FOLDER%%NAME%"

Creating a Folder Structure

If you pass a \-separated path to mkdir, intermediate folders are created as well. Any missing intermediate folders are created automatically.

Note

This behavior depends on command extensions, which are enabled by default in Windows.

Executing from Command Prompt

This creates the structure disposable > first > second in the current directory. Folders that do not exist are created.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>mkdir disposable\first\second

Executing from a Batch File

@echo off
setlocal

set FOLDER=%userprofile%\Documents\
set TREE=disposable\first\second

mkdir "%FOLDER%%TREE%"

endlocal
exit /b

Creating Multiple Folders at Once

To create several folders at once, combine mkdir with the for command.

Executing from Command Prompt

This example creates five numbered folders: “disposable1”, “disposable2”, and so on.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>for %i in (1,2,3,4,5) do mkdir disposable%i

Executing from a Batch File

Caution

Inside a batch file, write the for variable with two percent signs, %%i, instead of %i.

@echo off
setlocal

set FOLDER=%userprofile%\Documents\

for %%i in (1,2,3,4,5) do (
  mkdir "%FOLDER%disposable%%i"
  echo Created folder number %%i
)

endlocal
exit /b

For more information about the for command, see the following page:

Creating a Folder Named with the Date

To create a folder named after the date (for backups, for example), slice the %date% variable.

Create
mkdir "%date:~0,4%%date:~5,2%%date:~8,2%"
Caution

The format of %date% depends on the Windows regional settings. The example above assumes the Japanese 2026/11/18 format. In formats such as the en-US Wed 11/18/2026, every offset shifts. Adjust the slice positions to match your environment.

Why a Folder Cannot Be Created

Error messageMain cause and fix
A subdirectory or file already exists.A folder (or file) with that name exists. Check with if not exist
Access is denied.A location that requires administrator rights, such as the root of C:\ or C:\Program Files. Change the destination or run as administrator
The system cannot find the drive specified.The drive letter does not exist

In a batch file, you can detect whether mkdir failed (exit code other than 0).

mkdir "%FOLDER%%NAME%" || echo Failed to create the folder
Note

PowerShell also has mkdir, but it is a function that calls New-Item -ItemType Directory. The basic usage is the same, yet it is not the same as mkdir in Command Prompt.

Confirmation Test

Practice Problem

You ran the following command in a folder that contains no files. Select the correct result.

mkdir disposable\first\second

Choose one answer.

  1. The disposable folder is created, with first inside it and second inside that
  2. The disposable folder is created, but an error occurs because first and second do not exist
  3. An error occurs because the disposable folder does not exist
#Command Prompt #Batch Files #Command