Create a New Folder

Maintained on

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.

チェック

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).

- □ ×
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.

チェック

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
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

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

チェック

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:

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
チェック

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