How To Create A File In Command Prompt?

478 Views
0 rating based on 0 reviews

Have you ever wondered how to create a file in command prompt? Maybe you've wondered how you can create multiple files in the same folder, or maybe you've wondered how you can tell command prompt to always open with a specific file. This article is going to cover exactly that. You will find out how to do all three things and more!
Typically, you can create new files quickly from File Explorer. For most people, this is enough. However, you can apply Command Prompt or PowerShell tools to create files or folders when it doesn’t work.

Create a File in Command Prompt

Creating a File in Command Prompt

  1. You can apply the “echo” command or the “fsutil” command to create a file. If you wish to make a file that contains content in it, then “echo” is applicable and for creating a file with a particular size or blank file, apply the “fsutil” command.
  2. Select the “Start” menu and put “cmd” in the search field. Access the “Command Prompt” application from the search results.
  3. For initiating the “echo” command, put “echo file text > sample.txt dir” in the command prompt window. Typically, this command echoes the “file text or any content of your selection” to the command program. However, as there is also a “redirection operator (>),” it will create a file with the “sample.txt” title.
  4. After creating the file, write the “dir” command to get the list of every file in the current working location.
    The created sample txt file
  5. You can check if the “sample.txt” file has the required contents by putting the “type” command with the file name next to it with a space. It will read the file and show you the contents.
  6. If the “echo” command doesn’t work, you can apply the “copy” command with the “con” factor to create a file. The “con” factor will direct the “copy” command to copy the output rather than copying the files.
  7. Put the “copy con” command in the command prompt with the file name like this: “copy con sample.txt.” It will not generate the file right away. It will display a flashing cursor.
  8. Then, put the text you need to add to the file and hit “Enter.” Click the “Control” and “Z” button together from your keyboard. Hit “Enter” to exit the window. It will show the “^Z” marker and the file copy confirmation.
    file copy confirmation
  9. If you wish to apply the “fsutil” command, then access the “Command Prompt” application selecting the “Run as administrator” option.
  10. Put the fsutil command with the file name and size in bytes like this: “fsutil file createnew sample.txt 1000”. It will generate a “sample.txt” file of 1kb size.
  11. Again, put the “dir” command to check the file, and you will get the window containing the “sample.txt” file.

Creating a Folder in Command Prompt

  1. Access “Command Prompt.” Put the “cd” command and destination of the folder beside it and tap “Enter.” Such as, if you wish to generate the folder on the desktop, then put “cd desktop”.
    Put the file destination location
  2. Put the “mkdir” command with the folder title and hit “Enter.” For example. To generate a folder titled “Homework,” the command line should be “mkdir Homework”.
    Generate a folder
  3. Tapping enter will process the command and create a folder.

Creating a File in PowerShell

  1. Access the “Windows PowerShell” application from the “Start” menu.
  2. Apply the “cd” command to access the destination location where you wish to create the file.
  3. Put this command “New-item - Path. -Name “filename.txt” -ItemType “file,” where change the file name, path, and type with your selected file name and type. It will generate a new file.

Summary: Create a File in Command Prompt

  • Click on Start. Go to All Programs>Accessories.
  • Right-click on Command Prompt.
  • Select Run as Administrator.
  • Type the word "cd" followed by a space and the path of the directory you want to open, then press ENTER. (Example: cd C:\Users\techycoach\Desktop)
  • To create a new text document, type "notepad filename.txt", replacing the italicized word with your desired file name (Example: notepad myfile.txt).
  • A new Notepad window will open with your desired file name already filled in for you next to "Save as type". You can type whatever content you like into this document and use File>Save to save it when finished. You can also use File>Save As to save a copy somewhere else or under a different file name.