≡ Menu

Mkdir: Create directory from command line

In Windows, we can create directories from command line using the command mkdir(or md). Syntax of this command is explained below.

Create a folder from command line:

mkdir foldername

For example, to create a folder named ‘newfolder‘ the command is:

mkdir newfolder

Create directory hierarchy

We can create multiple directories hierarchy(creating folder and sub folders with a single command) using mkdir command.
For example, the below command would create a new folder called ‘folder1’ and a sub folder ‘folder2’ and a sub sub folder ‘folder3’.

mkdir folder1\folder2\folder3.

The above command is same as running the below sequence of commands.

mkdir folder1
mkdir folder1\folder2
mkdir folder1\folder2\folder3

Permissions issue

Yoou need to have permissions to create folder for the command to work. Not having permissions to create folder would throw up ‘access denied’ error.

C:\Users>mkdir c:\Windows\System32\test
Access is denied.

If there exists a file or folder with the same name, the command throws up error.

C:\>md test
A subdirectory or file test already exists.

If you don’t see a file or folder with that name, make sure to check if it’s not hidden.

Handling whitespaces

If the name needs to have space within, you should enclose it in double quotes.
For example, to create a folder with the name ‘My data’, the command would be

c:\>mkdir "my data"

Creating multiple folders

mkdir command can handle creating multiple folders in one go. So you can specify all the folders you wanted to create like below

C:\>mkdir folder1 folder2  subfolder1/folder3 subfolder2/subfolder21/folder4

The syntax of the command is incorrect.

If you get this error, make sure you are using the directory paths in Windows format and not in Linux format. On Linux, the directory paths are separated with ‘/’, but in Windows it’s ‘\’.

c:\>mkdir  folder1/folder2
The syntax of the command is incorrect.

The right command is

c:\>mkdir  folder1\folder2
2 comments… add one
  • Guru

    And the command can also be used as ‘md’.

  • abdel kasem

    can your good comment start with get the command line first . to get the command line use 1- …
    2 – …
    3- ..
    and son
    now to use mkdir use the followin steps
    1- ..
    2-…
    3-…
    4-…
    and so on
    please assume who asked you knows nothing about operating system
    many thanks

Leave a Comment