4 Ways to Create a File Using Command Prompt on Windows

Wondering how to create a file using Command Prompt on Windows computers? This article will guide you on how you can easily do that.

We often find the need to create files and folders on our Windows computers to store various data types such as text, images, programs, and more.

While the Windows Graphical User Interface offers a user-friendly approach to do that, there are cases when using the Command Line Interface, specifically the Command Prompt, becomes essential.

Meanwhile, using the Command prompt to create a file on a Windows computer is equally uncomplicated. In the following sections, we will discuss how to create a file using Command Prompt on Windows PCs effortlessly.

How to Create a File With Command Prompt on Windows?

If, for any specific reason, you aim to create a file via Command Prompt on Windows, there are several approaches at your disposal.

Before initiating the file creation process with the Command Prompt — even if you are using File Explorer — it is necessary to navigate or move to the directory where you intend to keep the file.

Say you intend to create a file in the Desktop directory/folder, you need to navigate to the Desktop folder on your computer. When using Command Prompt, it initially opens to the User directory level.

Hence, you can switch to the Desktop folder, a subfolder of the User directory, by using the cd (change directory) command. This can be done by following these steps:

1. Press Windows + R to open the Run Command Box.
2. Type cmd in the box and hit Enter.

3. In the Command Prompt window, type cd Desktop and hit Enter to move to the Desktop folder. Immediately, you will have Desktop before the text cursor in the command prompt page showing that any command you will be running to create a file on the PC will be creating the file in the Desktop folder.

Change Directory

You can navigate to different folders using the command “cd folder name,” where the “folder name” part should be the name of the subfolder you wish to access and create a file in.

Additionally, to move to the directory where you want to save a new file, use the command “cd directory path.” For instance, you can type “cd C:\Users\Public\Pictures” to create a file in the CMD within the Pictures folder of the path used.

In a case when you want to create a new directory under your current directory level, you can do that by using the command below

mkdir directory_name

For example, to make a new folder/directory named MyFolder within the Desktop directory, enter the command mkdir MyFolder.

Subsequently, if you want to create a file using Command Prompt in this new folder, simply type cd new_directory_name. The command to be used in the case of our example above is cd MyFolder.

Note: You also can view the directories or folders within the current or opened directory level in the command prompt by executing the following command. Type dir in the command prompt and hit enter.

Having navigated to the directory you intend to store the file you wish to create, here are the potential methods to create a file using Command Prompt on Windows, according to your preferences:

Method 1. Create an Empty File Using Command Prompt

Command Prompt allows Windows users to effortlessly create an empty file of various types, such as png for images, docx for Word documents, txt for text files, and more. This command automatically produces the file in your present directory.

To create an empty file on your Windows PC using Command Prompt, input the following command and hit Enter:

type nul > filename.extension

Suppose I aim to create an empty Word document file named “EmptyDocs” at the Desktop directory level on my PC using Command Prompt. In that case, I would input the following command and press Enter:

type nul > EmptyDocs.docx

Therefore, the final part of the command – extension — will rely on the file format of the file you are creating.

Note: You can open the file created to confirm the method by entering filename.extension and pressing Enter.


Method 2. Creating a File Containing Certain Text

Another capability of the Command Prompt on Windows for file creation involves creating a file with specific text. This method is tailored for creating text files and includes the ability to input text directly through the command prompt, unlike the first method mentioned above, which only permits the creation of an empty file.

There are two commands you can use for this method and here are they:

echo command 

The echo command primarily showcases the text you input in the Command Prompt. However, it can also serve to generate a text file on Windows PCs, echoing the text entered with the command into the created file.

To use this command to create a text file with certain text, enter the following command and hit Enter:

echo the_text_to_input_in_the_file > filename.extension

For example, if you want to create a text file with the text “Thank you, Techworm”, simply enter the command below and hit Enter:

echo Thank you, Techworm > hello.txt

copy con command

Rather than using the echo command, an alternative method you can use is the copy con command. This also creates a text file with specific content on your PC. This process, however, follows a distinct sequence where you input the command first, run it, and then type the desired text into the file.

To employ the copy con command, initiate the text file creation and naming by entering the command below and pressing the Enter key:

copy con MyFile.txt

After that, type the text to be input in the file, press Ctrl + Z, then press Enter.

Your file will immediately be created in your current directory level.

Method 3. Creating a file of a certain size

You can easily create a file of a specific size using Command Prompt on Windows. This is a straightforward process and can be useful in various scenarios.

Just input the following command and press Enter:

fsutil file createnew filename.txt 1000

In the command, insert your desired file name in place of “filename,” while the digit at the end represents the file size in bytes.

Method 4. Creating Multiple Files

You can create multiple files in a folder at once by using the for loop command. This approach saves you the effort of manually creating numerous files with the same format one-by-one. This method can be used by entering the command below in your Command Prompt and pressing Enter:

for /l %a in (1 1 5) do type nul > "%a.txt"

This method uses the “type nul” command, as explained as the initial method in this article, enabling the creation of empty files in any format.

The (1 1 5) in the command instructs to create multiple files sequentially from 1 to 5 with an incremental step of 1. To generate a different number of files, such as 10, you would need to substitute the 5 with 10, adjusting accordingly for other quantities.

Also, the presence of .txt at the end of the command signifies the creation of text files. In a different scenario, such as wanting to create Word files, the command would need to be adjusted to::

for /l %a in (1 1 5) do type nul > "%a.docx"

The file created by this command will be saved in the directory where the command is executed.

In addition, you can assign a shared filename to multiple files rather than solely numbering them. You can do this by entering the following command and pressing Enter:

for /l %a in (1 1 5) do type nul > "filename %a.txt"

If you aim to name the files as TextFile-1, TextFile-2, and so on, the command to use would be:

for /l %a in (1 1 5) do type nul > "TextFile- %a.txt"

There you have it—five text files generated with just one command.

Wrap Up

The methods we covered above are some of the options for creating a file with Command Prompt on Windows. You can utilize any of the methods based on what you want to accomplish.

Additionally, you can delete files on your Windows PC using the Command Prompt as long as the file is under your current directory level. To do this, simply type Del filename.extension and press Enter.

Subscribe to our newsletter

To be updated with all the latest news

A tech junkie, and music fan. I love writing Reviews, How-to, and explainer articles related to Android, iOS, and Windows. If I'm not on my laptop brainstorming ideas for content, you'll most probably see me watching Tv shows or streaming videos on Youtube. Don't forget to follow me on Twitter as @Luqqman14


Please enter your comment!
Please enter your name here

Subscribe to our newsletter

To be updated with all the latest news

Read More

Suggested Post