Create a New Folder

Maintained on

Do you ever find yourself repeatedly creating a specific folder structure while using your computer or for work?

Or perhaps you have to manually create folders with sequential numbering one by one.

This page will show you how to create folders using the command prompt. The same steps can be followed to create folders using batch files.

Command to Use

To create a folder, use the mkdir command. The details of the command are as follows:

mkdir <folder name>

There are no options, only an argument specifying the folder name.

It may be helpful to remember this command along with its counterpart, rmdir.

For more information on rmdir, please refer to the following page.

There are also abbreviated versions of the mkdir command, but they perform the same function.

Executing from Command Prompt

This is an example of creating a folder named “disposable” directly under the user directory.

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

Executing from a Batch File

@echo off
setlocal

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

mkdir %FOLDER%%FILE_NAME%

endlocal
exit

Creating Folder Structures

When passing a string containing a slash as an argument to the mkdir command, it is possible to create folders within the created folder.

If the intermediate folder does not exist, it will be created anew.

Executing from Command Prompt

Create a folder structure under My Documents that looks like disposable > first > second.

If any of the folders do not exist, they will be created anew.

×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2024 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

Creating Multiple Folders at Once

To create multiple folders at once, you can use the for-in loop in conjunction with the mkdir command.

Executing from Command Prompt

This is an example of creating five folders named “disposable1”, “disposable2”, and so on, directly under the user’s My Documents directory.

Executing from a Batch File

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

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

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

endlocal
exit

Confirmation Test

Practice Problem

You executed the following command when there were no files in the folder. Please select the correct execution result.

mkdir disposable/first/second
回答がサーバーに送信されることはありません
#PowerShell #Command Prompt #Batch Files