Although this approach may seem easier in practice, especially if you’ve no previous experience with CLI, it has its shortcomings. Unlike the CLI way, which provides a quick and efficient way to create files on your computer, a GUI approach involves multiple steps, making it time-consuming and inefficient. So here’s a guide to walk you through the different methods you can use to create a file in Windows (be it Windows 11, Windows 10, Windows 8, or Windows 7) with Command Prompt.
How To Create a File in Windows With Command Prompt
Command Prompt or CMD is a powerful Windows utility that allows you to perform various system operations on your computer with ease. It’s pre-installed on the system and lets you run commands for a multitude of actions, everything from file management to running batch files for task automation. Creating files happens to be one such task, which you can perform more quickly and efficiently with the CMD prompt than using the File Explorer. But before we jump in and demonstrate how to create a file in Command Prompt, you must know how to navigate the Windows directory structure on it so you can create files in your desired folder.
Navigating Windows File System Using Command Prompt
To navigate the Windows file system with CMD, first, open the Command Prompt. For this, press the Windows + X keyboard shortcut and select Command Prompt from the menu.
Next, enter the dir command to list all the files and directories (or folders) inside a folder. Once you’ve identified the folder you want to open, enter the following command and press Enter:
cd folder_name
Eg: cd Documents
To go back to the parent directory, run: cd ..
For accessing the root directory: cd
While we’re at it, you should also know that you can create directories (or folders) using the Command Prompt. For this, use the cd command to navigate to the folder where you want to create a new folder and use the following syntax:
mkdir directory_name
For example, to create a directory name MyDocs, run: mkdir MyDocs
Finally, when you’re in the folder where you want to create a file, use any of the following methods to create files with CMD.
Creating a File Using echo Command
The echo command displays messages you type into the CMD window. However, when used with the redirection operator (>), it doubles as a file creation command that creates a file out of your inputted text. For creating a file using the echo command, open the Command Prompt and enter your command using the following syntax: echo your_text_here > filename.extension For example, if you want to create a text file named MyFile with This is sample text as its text and .txt as the file extension, you’d run: echo This is sample text > MyFile.txt Once you’ve created the file, verify that it has been created successfully by running: type filename.extension Eg: type MyFile.txt
Creating a File Using copy con Command
Unlike the echo command, which takes your input for the content of the file you’re creating at the outset, the copy con command takes a rather different approach. With it, you only need to give a name to your file initially. And, it then opens the new file in a text editor, where you can populate it with text. To create a file using copy con, use the syntax below: copy con filename_with_extension Eg: copy con MyFile.txt It will now put you inside the file in Command Prompt window itself, where you can add your desired text to it. Once you’ve done that, hit Ctrl + Z to save the file and Ctrl + C to exit editing.
Creating a File in Notepad Using Command Prompt
While both methods we’ve mentioned so far work well, they are not ideal for when you want to enter long text paragraphs into your text file. An alternative way to deal with this is to use Notepad, which you usually use to create files, but via the Command Prompt. For this, enter your command in the CMD window using the following syntax and hit Enter: notepad filename.extension For example, if you want to create a file named SampleDoc, you’d run: notepad SampleDoc.txt After this, CMD will open the file in Notepad. It will prompt you to create a new file since the file you enter doesn’t exist. Click Yes to accept and create the file. Now, just like how you would use Notepad, enter your text to the file and hit Ctrl + S to save and Ctrl + W to close the file.
Creating Multiple Files Using Command Prompt
For times when you want to create multiple files inside a folder at once and populate them later, you can use the for loop as shown in the following syntax: for /l %a in (1 1 10) do type nul > “%a.txt” …where (1 1 10) tells the CMD to perform the task in the sequence from 1, in steps of 1, up to 10. To create 20 files, replace 10 with 20 in your command. If you want to add a common name to the start of every file and follow that up with a number, you’d need to use the following syntax: for /l %a in (1 1 10) do type nul > “filename %a.txt” …where you need to replace filename with the name you’d like to give your files. For example, running the command below will create 10 blank files in the following name syntax: MyDoc-1. for /l %a in (1 1 10) do type nul > “MyDoc-%a.txt” Besides, if you want to create multiple files with the same text, you can tweak the command to incorporate the same action. To do this, instead of including do type nul, you need to use do echo your_desired_text. For example, if you want to create 10 files named MyDoc-1.txt, MyDoc-2.txt,… and so on with This is sample text as text, you’d run: for /l %a in (1 1 10) do echo This is sample text> “MyDoc-%a.txt” …and it will create them in your current directory.
Efficiently Creating Files on Windows With Command Prompt
The methods listed in this guide should help you with pretty much all sorts of file creation tasks in Command Prompt, be it creating single-line text files, multiple paragraph text files, or even multiple files with custom text and file names. So depending on requirements, you can choose a method accordingly and create files on Windows quickly and efficiently.
1. How do I create a text file in Windows command line?
Creating a text file in Windows is pretty straightforward, and you have a few different ways to go about it. If all you need is a simple one-line text file, you can use the echo command, whereas if you want to create a text file with multiple lines of text, you can either use the copy con command or create the file in Notepad. Lastly, if you want to create multiple text files, you can use the for loop.
2. Which command is used to create a file?
Microsoft offers a few different CMD commands to create a file, such as echo and copy con. However, you can also use other methods, wherein you can either create a file in Notepad or run a for loop to generate multiple files with your desired name and file name.