MKDIR: Creates a directory.


 


... The examples for the command "MKDIR"
... "MKDIR" Excerpt from Microsoft Windows Help
... Important information, tips for the "MKDIR" command

The command: "MKDIR" is on Windows 12, 11, 10, .. , MS Server 2025, 2022, 2019, .. available

The examples for the command "MKDIR"

The `MKDIR` commands can be used in the same way as the `MD` commands as they are synonymous. Here are some examples of using `MKDIR`: Example 1: Create a single directory:

@ECHO OFF
MKDIR NewFolder

Description: This command creates a directory named "NewFolder" in the current working directory. Example 2: Create multiple nested directories:

@ECHO OFF
MKDIR FirstDirectory\SecondDirectory\Subdirectory

Description: Three nested directories are created here: "FirstDirectory", "SecondDirectory" and "SubDirectory". The command automatically creates the required parent directories. Example 3: Create directory with absolute path:

@ECHO OFF
MKDIR C:\MyDirectory

Description: A directory with the absolute path "C:\MyDirectory" is created here. Example 4: Creating directories and changing to the newly created directory at the same time:

@ECHO OFF
MKDIR NewDirectory && CD NewDirectory

Description: The command creates a directory named "NewDirectory" and then changes to that directory. Example 5: Check if the directory already exists before creating it:

@ECHO OFF
IF NOT EXIST MyDirectory MKDIR MyDirectory

Description: This checks whether the “MyDirectory” directory already exists. If not, it is created using the `MKDIR` command. Example 6: Create directories and ignore errors if they already exist:

@ECHO OFF
MKDIR MyDirectory 2>NUL

Description: The command creates the directory "MyDirectory" and ignores error messages (if the directory already exists) with `2>NUL`. The `MKDIR` commands are equivalent to the `MD` commands and can be used depending on personal preference. The principles and considerations above apply equally to both commands.

"MKDIR" Excerpt from Microsoft Windows Help

Microsoft Windows [Version 10.0.19045.3693]
(c) Copyright 1985-2023 Microsoft Corp.

C:\\WINDOWS>

Creates a directory.

MKDIR [drive:]path
MD [drive:]path

If Command Extensions are enabled MKDIR changes as follows:

MKDIR creates any intermediate directories in the path, if needed.
For example, assume \a does not exist then:

    mkdir \a\b\c\d

is the same as:

    mkdir \a
    chdir \a
    mkdir b
    chdir b
    mkdir c
    chdir c
    mkdir d

which is what you would have to type if extensions were disabled.

Important information, tips for the "MKDIR" command

There are a few important points to note when using the `MKDIR` command in the Windows Command Prompt: 1. Permissions: You need appropriate permissions to create directories in the specified path. Make sure you have the necessary rights to create directories. 2. Colon: The `MKDIR` command creates a single directory or multiple nested directories. The syntax is: `MKDIR [directory]`. Note that there is no colon (`:`) like there is in a label. 3. Existing Directories: If you try to create a directory with `MKDIR` and the directory already exists, you will get an error. You can get around this using the `IF NOT EXIST` check to check if the directory already exists before creating it.

    IF NOT EXIST MyDirectory MKDIR MyDirectory
    
4. Nested Directories: The `MKDIR` command automatically creates parent directories if they do not exist. So you can create nested directories by specifying the full path.

    MKDIR First\Second\Subdirectory
    
5. Error Handling: If you want the script to continue even if a directory already exists, you can redirect the error output stream.

    MKDIR MyDirectory 2>NUL
    
Here, the error output (error level 2) that might occur if the directory already exists is redirected to the null devices (NUL) and you don't get a visible error message. 6. Current Working Directory: The `MKDIR` command creates the directory in the current working directory. You can use the `CD` command to change the current working directory before creating a directory if you want it to be created in a different location.

    CD C:\Example
    MKDIR New Directory
    
It is important to ensure that the syntax of the `MKDIR` command is correct and that you have the necessary permissions to create directories. Also note that error handling and checking for existing directories are often useful in batch scripts to avoid unexpected problems.


Deutsch
English
Español
Français
Italiano
日本語 (Nihongo)
한국어 (Hangugeo)
汉语 (Hànyǔ)
Türkçe
Português
Português
Svenska
Norsk
Dansk
Suomi
Nederlands
Polski









Windows-10


... Windows 10 FAQ
... Windows 10 How To


Windows 10 How To


... Windows 11 How To
... Windows 10 FAQ



The command MKDIR - Creates a directory.

HTTP: ... console109.000000ko0.000000index.htm/en/041.htm
0.093
11313
WINDOWS SETTING MS SETTINGS WINDOWSDEFENDER
WINDOWS SETTING MS SETTINGS PRIVACY LOCATION
WINDOWS EINSTELLUNG MS SETTINGS REGIONLANGUAGE
What is a binary number?
Environment Variables?
Was ist eine ISO Datei?
WINDOWS SETTING MS SETTINGS PRIVACY
What is a virtual PC?
Was ist ein Zauberwürfel?
What is adware?



(0)