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
From the command line, Windows allows us to create directories using the mkdir (or MD) command. Here is an explanation of how to use this command.
The command line is used to create a folder:
mkdir foldername
Using the following command, you can create a folder named “newfolder”:
mkdir newfolder
The hierarchical structure of the directory:
With the mkdir command, we can create hierarchies of multiple directories (creating folders and subfolders all at once).
In the example below, folder 1 would be created as well as a subfolder called folder 2.
mkdir folder1\folder2\folder3.
You can run the sequence of commands below with the above command.
mkdir folder1 mkdir folder1\folder2 mkdir folder1\folder2\folder3
Problems with permissions:
For this command to be effective, you will need permission to create a folder. A folder cannot be created if its permissions are not granted.
C:\Users>mkdir c:\Windows\System32\test Access is denied.
A command that attempts to run against a similar file or folder will result in an error.
C:\>md test A subdirectory or file test already exists.
Make sure you haven’t hidden any files and folders with that name if you don’t see them.
A guide to handling whitespace:
Please enclose the name within double quotes if there is to be a space within it. You would type the commands below to create a folder named “My data”
c:\>mkdir "my data"
How to Create multiple folders?
Create multiple folders with the mkdir command. The following are the instructions you can follow to create all the folders that you want to create.
C:\>mkdir folder1 folder2 subfolder1/folder3 subfolder2/subfolder21/folder4
That command is incorrect in its syntax:
Using Linux-formatted pathnames causes this error. Use Windows pathnames instead. When browsing directories on Linux, the paths are separated by a ‘/’, but on Windows, they are separated by a ‘\’.
c:\>mkdir folder1/folder2 The syntax of the command is incorrect.
As a rule of thumb, you should:
c:\>mkdir folder1\folder2
FAQs –
Question: What is mkdir in CMD?
Answer: The process of creating a new directory or subdirectory. By default, command extensions allow you to create intermediate directories by using the mkdir command in a specified path. There is no difference between this command and md. You understand how to use mkdir command prompt.
You may also like: How to Rename File in CMD [Command Prompt]
Download Article
Download Article
Learning how to do simple file management at the Command Prompt (cmd) comes in handy when you’re learning to code. When you create files and folders at the command line, you can access, use, and manipulate those folders and files in Windows apps. We’ll show you how to create folders (directories) and text files at the Windows Command Prompt, and teach you commands for deleting unneeded files and folders.
-
Open the Command Prompt. The easiest way to do this is to press Win + S to activate the search bar, type cmd, and then click Command Prompt in the search results.
-
The prompt will open to C:\Users\YourName by default. If the directory is somewhere else, type cd path_to_directory and press Enter. Replace path_to_directory with the actual directory location.[1]
- For example, if you want to create a file on the Desktop, type cd desktop and press Enter.
- If the directory you’re looking for isn’t in your user directory (e.g., C:\Users\YourName), you’ll have to type in the whole path (e.g., C:\Users\SomeoneElse\Desktop\Files).
Advertisement
-
If you don’t want to create an empty file, skip to the next step.[2]
To create an empty file:- Type type nul > filename.txt.
- Replace filename.txt with whatever you want to call your new file. The «.txt» part indicates that this is a plain text file. Other common file extensions include «.docx» (Word document), «.png» (empty photo),and «.rtf» (rich text document). All of these file types can be read on any Windows computer without installing additional software.
- Press Enter.
-
If you don’t want to create a file with certain text inside, skip to the next step.[3]
Use these steps to create a plain text file that you can type into:- Type copy con testfile.txt, but replace testfile with the desired file name.[4]
- Press Enter.
- Type some text. This is a rudimentary text editor, but it’s good for quick notes or code. You can use the Enter key to go to the next line.
- Press Control + Z when you’re finished editing the file.
- Press the Enter key. You’ll see «1 file(s) copied,» which means your file is now saved with the name you created.
- Another way to do this is to run this command: echo enter your text here > filename.txt.
- Type copy con testfile.txt, but replace testfile with the desired file name.[4]
-
If you don’t want to create a file that’s a specific size, skip this step.[5]
To create a blank text file based on byte size, use this command:- fsutil file createnew filename.txt 1000.
- Replace filename with the desired file name, and 1000 with the actual number of bytes you’d like the file to be.
Advertisement
-
The easiest way to do this is to press Win + S to activate the search bar, type cmd, and then click Command Prompt in the search results.
-
Go to the directory containing the file you want to delete. The prompt will open to C:\Users\YourName by default. If the file is somewhere else, type cd path_to_directory and press Enter. Replace path_to_directory with the actual directory location.
- For example, if you want to delete a file from the Desktop, type cd desktop and press Enter.
- If the directory you want to view isn’t in your user directory (e.g., C:\Users\YourName), you’ll have to type in the whole path (e.g., C:\Users\SomeoneElse\Desktop\Files).
-
This displays a list of all files in the current directory. You should see the file you want to delete in this list.
- Using Command Prompt to delete files results in the files being deleted permanently rather than being moved to the Recycle Bin. Exercise caution when deleting files via Command Prompt.
-
Replace filename with the full name and extension of the file you want to delete.[6]
File names include file extensions (e.g., *.txt, *.jpg). This deletes the file from your computer.- For example, to delete a text file entitled «hello», you would type del hello.txt into Command Prompt.
- If the file’s name has a space in it (e.g., «hi there»), you will place the file’s name in quotations (e.g., del "hi there").
- If you get an error that says the file cannot be deleted, try using del /f filename instead, as this force-deletes read-only files.
Advertisement
-
The easiest way to do this is to press Win + S to activate the search bar, type cmd, and then click Command Prompt in the search results.[7]
-
The prompt will open to C:\Users\YourName by default. If you don’t want to create a new directory here, type cd path_to_directory and press Enter. Replace path_to_directory with the actual directory location.[8]
- For example, if you want to create a directory on your Desktop, you would type in cd desktop and press Enter.
- If the directory you’re looking for isn’t in your user directory (e.g., C:\Users\YourName), you’ll have to type in the whole path (e.g., C:\Users\SomeoneElse\Desktop\Files).
-
Replace NameOfDirectory with the name of the directory you wish to create.[9]
- For example, to make a directory named «Homework», you would type mkdir Homework.
-
This runs the command to create a folder with the desired name.
Advertisement
-
The easiest way to do this is to press Win + S to activate the search bar, type cmd, and then click Command Prompt in the search results.[10]
-
The prompt will open to C:\Users\YourName by default. If the directory you want to delete is somewhere else, type cd path_to_directory and press Enter.[11]
Replace path_to_directory with the actual directory location.- For example, if you want to delete a directory from your Desktop, type cd desktop.
- If the directory isn’t in your user directory (e.g., C:\Users\YourName), you’ll have to type in the whole path (e.g., C:\Users\SomeoneElse\Desktop\Files).
-
Replace DirectoryName with the name of the directory you want to delete.[12]
- For example, if you’re trying to delete your «Homework» folder, you’d type in rmdir /s Homework here.
- If the directory’s name has a space in it (e.g., «Homework assignments»), place the name in quotations (e.g., rmdir /s "Homework assignments").
-
[13]
- If you try to delete a directory that contains hidden files or directories, you’ll see an error that says «The directory is not empty.» In this case, you’ll have to remove the «hidden» and «system» attributes from the files inside the directory. To do this:[14]
- Use cd to change into the directory you want to delete.
- Run dir /a to view a list of all files in the directory and their attributes.
- If you’re still okay with deleting all of the files in the directory, run attrib -hs *. This removes special permissions from the undeletable files.
- Type cd .. and press Enter to go back one directory.
- Run the rmdir /s command again to delete the folder.
- If you try to delete a directory that contains hidden files or directories, you’ll see an error that says «The directory is not empty.» In this case, you’ll have to remove the «hidden» and «system» attributes from the files inside the directory. To do this:[14]
-
This will permanently remove the directory.[15]
Advertisement
Add New Question
-
Question
How can I create directories?
Subhodeep Roy
Community Answer
If you are creating a directory in C drive, the command will be»C:\MD {the name of the directory/folder}» then press Enter.
-
Question
How do I create a folder using CMD?
Navigate to where you want the subfolder created and type «mkdir «.
-
Question
How do I create a test file under the sub folder?
Change directory into the new sub folder and then on the next line, create your new test file. For example: cd mysubfolder $ type nul > newtextfile.txt
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Video
Thanks for submitting a tip for review!
-
Using Command Prompt to delete files results in the files being deleted permanently rather than being moved to the Recycle Bin. Exercise caution when deleting files via Command Prompt.
Advertisement
References
About This Article
Article SummaryX
1. Use the mkdir command to create a folder.
2. Use rmdir /s to delete a folder.
3. Use the copy con or echo command to create a file.
4. Use del to delete a file.
For tips on how to create a file inside a folder, read on!
Did this summary help you?
Thanks to all authors for creating a page that has been read 1,585,448 times.
Is this article up to date?
The Windows file system is organized in a tree-like structure. At the base, or root, of the tree are drives. Drives are typically given a letter to designate them. Conventionally drive letters A: and B: are used for floppy disk drives, C: is used for the local hard disk drive, D: is used for the local CD or DVD drive, and higher letters are used for network or removable drives.
Under each drive you can have a series of directories (AKA Folders), subdirectories (a directory inside of another directory), and files.
In the Windows command prompt (cmd), the directory you are currently in is known as your current working directory.
Displaying your current working directory
From the Windows Command Prompt use the cd command to display your current working directory:
In Windows, your current working directory is also typically displayed as part of the prompt.
Changing directories in Windows cmd
The cd command is also used to change directories, just type cd followed by the directory path you want to make your current working directory. In the following example we change from the c:\Users directory to the c:\Users\Wizard directory:
c:\Users>cd Wizard
c:\Users\Wizard>
If you want to change to a directory that has spaces in the name you should put double quotes around the directory name, if you don’t, you will receive an error in some versions of Windows. Here we change to the Book of Spells directory, note the use of double quotes around the name:
c:\Users\Wizard>cd "Book of Spells"
c:\Users\Wizard\Book of Spells>
commands, directories, and file names in Windows are case-insensitive, meaning it does not matter if you type them using uppercase or lowercase letters.
If you need to change directories to a root drive (i.e. C: drive, D: drive, etc) be sure to include a backslash after the drive letter:
c:\Users\Wizard>cd c:\
c:\>
If you do not include the backslash after the drive letter the cd command will just display your current working directory and will not actually change to the new directory:
c:\Users\Wizard>cd c:
c:\Users\Wizard
c:\Users\Wizard>
Directory traversal
As a shortcut, you can use cd and double-periods to traverse to the parent directory of your current working directory. For example, suppose you are in the c:\Users\Wizard\Book of Spells directory. If you want to change to the c:\Users\Wizard parent directory you could do this:
c:\Users\Wizard\Book of Spells>cd c:\Users\Wizard
c:\Users\Wizard>
Or you can use cd .. to achieve the same result:
c:\Users\Wizard\Book of Spells>cd ..
c:\Users\Wizard>
If you need to move up two or more parent directories simply add additional double-periods separated by a backslash. For example, to move up two directories from Book of Spells to Users:
c:\Users\Wizard\Book of Spells>cd ..\..
c:\Users>
Creating a directory
You can use the mkdir command followed by a name to create a directory. For example, to create a new directory inside of the current working directory called one-liners:
c:\Users\Wizard\Book of Spells>mkdir one-liners
Once created, you can cd to the directory as you normally would:
c:\Users\Wizard\Book of Spells>cd one-liners
c:\Users\Wizard\Book of Spells\one-liners>
Links and Resources
-
Windows cd Command
Not many Windows users are familiar with CMD. The common misconception is that only programmers and computer geeks use CMD. Basically, CMD is a tool that you can use to communicate with your Windows computer. Though the user interface and other input methods are introduced, CMD is one tool that you cannot take for granted. Some commands, such as creating folders, are easier to execute using CMD. You may laugh and think that it is harder to create a folder using CMD instead of using your mouse and the “Right click > New folder” method. You may have a point, but what if you are asked to create 10 folders or more? CMD would greatly simplify the task. Creating a folder using CMD is easy. This article will show you how.
Create a Folder Using CMD in Windows
To use CMD to create a folder on your Windows computer, follow these steps:
1.Click on the Search button located on the lower-left part of your computer’s screen.
2.In the Search box, type in CMD.
3.Open CMD from the results.
4.With CMD opened, go to the drive where you want to put the folder. To go to the drive, type in the name of the drive followed by the colon (:) symbol. In this case, we want to go to Drive D so we input D:.
5.CMD’s directory will change to the chosen drive. Type in the MKDIR command to create a directory or folder. In this case, we want to make a folder named TECHRECIPE, so we type in mkdir TECHRECIPE into CMD.
6.You are done. You can go to the newly created folder using CMD by typing in the command CD followed by name of the folder. In this case, type in CD TECHRECIPE in CMD.
7.You can also use your computer’s user interface to see that the folder has been created.
Create Multiple Folders Using CMD in Windows
To create multiple folders using CMD, follow these steps:
1.Open CMD on your Windows computer.
2.Go to the directory or folder where you want to create the multiple folders. In this case, we will go to the newly created folder.
3.Type in the MD command, followed by the names of the folders that you want to create. In this case, we want to create four folders named TR1, TR2, TR3 and TR4. Therefore, we input md TR1 TR2 TR3 TR4.
4.The subfolders will be created. You can go to the folder using your computer’s user interface, and you will see that all the subfolders have been created.
5.You are done.
Learning CMD is easy. If you want to know more about using CMD or if you have questions concerning any of the steps above, let us know in the comments section.
Leomar Umpad
A supply chain operations manager by profession. A technology-lover and a writer by heart. I have the passion to teach and inform.
