How to create a file in MS-DOS and the Windows command line

Windows command line (DOS)The following sections contain information on the various ways to create a file in MS-DOS or from the Windows Command Prompt. To proceed, you may read through each section in order or select from the below list.

Edit command
Copy con command
Start command
Listing the file after created

With the edit command

Note: 64-bit versions of Windows do not include the edit command. Instead of using edit, use the start command mentioned below.

edit myfile.txt <press enter>

If available and done properly you should see a window similar to the example below.

MS-DOS Editor edit command window

Once you have typed the information for the file myfile.txt, click File and choose exit. If you do not have a mouse, see the edit command page for keyboard shortcuts and other navigation tips.

After clicking exit, if any changes were made the computer will prompt you if you want to save the file, click Yes and the file will be created or overwritten with the new changes.

With copy con command

If you are running an MS-DOS version 4.x or lower or you cannot use the edit or the start method you can also use copy con to create a file, as shown below.

copy con myfile.txt <press enter>

Upon executing the above command, the cursor moves down one line to a blank line, allowing you to create the new file line by line. Once you are ready to create the file, press Enter to get to a blank line, press and hold Ctrl, press Z, and then let go of both keys. Once ^Z is shown on the screen press Enter to save the file and exit.

Note: Using the copy con method is a very basic method of creating a file that does not give you the ability to edit a file, or go back and fix any errors made while creating the line.

With the start command

start notepad myfile.txt <press enter>

The Windows Notepad and any text editor can also be started to create a file from the command line. Entering the above command would use the start command to run Notepad and create the myfile.txt. Once the file was saved in Notepad, that file would be created in the same directory as where the command was ran.

How to list the file once created

After the file has been created using any of the above methods, you can list it by using the dir command.

Additional information