Create a New Folder
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).
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.
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.

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

60分でわかる! 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.
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: