How to Create a Folder or File from Windows Command Prompt

Windows Command Prompt (CMD) is a powerful tool for running commands and performing various tasks on your computer. One of its fundamental functions is to create folders and files from the command line. In this article, we’ll explore how to create folders or files using Windows Command Prompt. However, let’s first understand why you might want to utilize CMD for this purpose.

Create a Folder or File from Windows Command Prompt

Creating folders or files using the Command Prompt can be advantageous for several reasons. One of the most common reasons is to manage computers remotely or servers through command-line interfaces and quickly create a folder or a file without navigating through the graphical interface.

Now that we know the benefits of creating folders and files with CMD, let’s proceed with the article to learn how to do it effectively using command-line commands.

How to Create Folders From CMD in Windows

Creating folder(s) using CMD in Windows may sound tricky, but it is not. The steps are pretty simple and straightforward to execute. We have separated the steps based on whether you are creating a single or multiple folders.

Let’s begin with a command line for a new folder. 

How to Create a Single Folder Using CMD

Step 1: Press the Windows key on your keyboard, type Command Prompt, and click open.

type Command Prompt

Step 2: Now, it is time to select the destination where you want to create a new folder. Type the below command and hit enter.

Note: In place of YourDirectoryPath below, enter your specified destination path. For example, if you want to create a folder on the Desktop, type cd desktop and press Enter.

cd YourDirectoryPath
Type the below command and hit enter

If you change your mind and want the directory to be changed, type the drive name with the colon (:) symbol (example- D:) and hit Enter. 

Step 3: Once you have reached the desired destination, type the below command and press Enter.

Note: Replace NameofYourDirectory with the folder’s name (for example- Games or Personal Files or Movies, etc.) 

mkdir NameofYourDirectory
Once you have reached the desired destination

That’s it. You have successfully created a single folder on your Windows computer using Command Prompt. If you are looking to create multiple folders or subfolders, continue reading.

Also Read: Difference between Command Prompt and Powershell

How to Create Multiple Folders or Subfolders

We will demonstrate how to create three folders at the same time. You can, however, create as many folders as you wish, provided the folder names are distinct. 

Step 1: Press the Windows key on your keyboard, type Command Prompt, and click open.

type Command Prompt

Step 2: Now, it is time to select the destination where you want to create a new folder. Type the below command and hit enter. 

Note: In place of YourDirectoryPath below, enter your specified destination path. For example, if you want to create a folder on the Desktop, type cd desktop and press Enter.

cd YourDirectoryPath
Type the below command and hit enter

If you change your mind and want the directory to be changed, type the drive name with the colon (:) symbol (example- D:) and hit Enter. 

Step 3: Once you have reached the desired destination, type the below command and press Enter.

Note: Replace NameofYourDirectory with the name of the folder. For example, it can be Games, Document, and Movies. Ensure you keep a gap between the folder (directory) names. 

mkdir NameofYourDirectory1 NameofYourDirectory2 NameofYourDirectory3 
type the below command

There you go. You have successfully created a folder using the Windows Command Prompt. Continue with the steps below if you want to create a subdirectory using CMD.

Step 4: You know the name of the folders you created. First, you must choose the folder you want subfolders in, type the below command, and hit Enter.

cd NameofYourDirectory
choose the folder you want subfolders in

Step 5: In the directory where you want to create subfolders, type the following command and press Enter.

Note: You can have multiple subfolders in a single folder. However, be sure to leave a gap between the folder name (directory).

md NameofSubDirectory1 NameofSubDirectory2 NameofSubDirectory3
multiple subfolders in a single folder

There you have it. The subfolders are created under the folder you want. You can repeat the above steps to create multiple subfolders in multiple folders. 

Keep reading if you want to take it further and create a file in cmd.

How to Create a File Using CMD in Windows

Much like creating a folder using Command Prompt, creating a file in CMD is no different, provided you understand the basics of finding and locating your destination directory and name the file distinctly.  

Let’s begin with creating an empty file using the Windows Command Prompt.

How to Create an Empty File

Step 1: Press the Windows key on your keyboard, type Command Prompt, and click open.

type Command Prompt

Step 2: Now, it is time to select the destination where you want to create a new folder. Type the below command and hit enter. 

Note: In place of YourDirectoryPath below, enter your specified destination path. For example, if you want to create a folder on the Desktop, type cd desktop and press Enter.

cd YourDirectoryPath
Type the below command and hit enter

Step 3: Now that you are in the destination directory, type the below command and press Enter.

Note: Replace the filename with the name you want, and ‘.FileExtensions’ should be set to the file extension, such as .txt, .docx, etc.

type nul > filename.FileExtensions
Replace the filename with the name you want

That’s about it. An empty file will be created with the set extension for you to check and work on later. If you want to create a file containing some text using cmd, continue reading.

Also Read: Start Command Prompt as admin from Windows Task Manager

How to Create a File Containing Some Text

Step 1: Press the Windows key on your keyboard, type Command Prompt, and click open.

type Command Prompt

Step 2: Now, it is time to select the destination where you want to create a new folder. Type the below command and hit enter. 

Note: In place of YourDirectoryPath below, enter your specified destination path. For example, if you want to create a folder on the Desktop, type cd desktop and press Enter.

cd YourDirectoryPath
Type the below command and hit enter

Step 3: Now, in the destination directory, type the below command and press Enter.

Note: Replace the filename with the name you want, and ‘.FileExtensions’ should be set to the file extension, such as .txt, .docx, etc.

copy con filename.FileExtensions
type the below command and press Enter

Step 4: Type the text you want to put in the file. If you are entering multiple lines, use the Enter key. 

Example: This is a test writeup to test the method and create a file with content using Command Prompt.

use the Enter key

Step 5: Press ‘Ctrl + Z’ on your keyboard once you add text to the file and hit Enter.

Press 'Ctrl + Z' on your keyboard

With this, a new file will be created with the entered details, which you can access via File Explorer and edit further if required. If, for some reason, you are unable to execute the command, reach out to Microsoft Support and get the issue resolved.

If there is anything we have missed in the article, please refer to the FAQ section below. 

FAQs on Create and Delete a Folder Command Prompt

1. How do I delete a folder using Command Prompt?

To delete a folder and its contents, use the “rmdir” (remove directory) command followed by the folder path. For example: rmdir /s /q C:\Users\YourUsername\Desktop\OldFolder

2. What’s the difference between “rmdir” and “rd” commands?

Both “rmdir” and “rd” are used to remove directories. “Rmdir” is the full command, while “rd” is a shorthand version of it. You can use either command interchangeably.

3. Can I recover a folder I accidentally deleted using Command Prompt?

Once a folder is deleted using Command Prompt, it typically goes to the Recycle Bin, where you can restore it. If you’ve emptied the Recycle Bin, data recovery software may be necessary to attempt recovery.

Quick Create a File or Folder

Now that you know how to create a folder or file using Windows Command Prompt, you can quickly automate tasks, manage remote systems, create files, or enhance your command-line proficiency. You may also want to quickly install apps in Windows via the Command Prompt.

Was this helpful?

Thanks for your feedback!

Last updated on 10 October, 2023

Leave a Reply

Your email address will not be published. Required fields are marked *

The article above may contain affiliate links which help support Guiding Tech. The content remains unbiased and authentic and will never affect our editorial integrity.