Create and Delete Files and Directories from Windows Command Prompt

The Windows Command Prompt can be a great way to get tasks done quickly and efficiently. It is a very powerful and often overlooked tool in computing. The command prompt is a mouse free environment and it is ideal for those who prefer to do their work from the keyboard. In this article, you will be introduced to the Command Prompt and how to use it to complete some basic tasks. After reading this article you should be more comfortable with using the Command Prompt for basic tasks.

Steps

  1. Open the Windows Command Prompt. Click on the start screen of your computer and go to the search box. Type command prompt or cmd. Double click on Command Prompt from the list of results to open the command prompt. The command prompt will look like this: C:\users\Username>.
  2. Create a new directory. Use the mkdir command to create a new directory to work with. The command is mkdir -> directory name. In the example above, a new directory called wikihow was created by typing: mkdir wikihow.
  3. Change the current working directory. In order to move into the newly created directory, use the cd or change directory command. The command is cd -> directory name. In the example, cd wikihow was typed. Now the prompt looks like this: C:\users\Brian\wikihow> as shown above.
  4. Check the directory contents. In order to check the contents of the current directory, use the dir command. Simply type dir and press enter and a list of the directory contents will be displayed as shown. In the example the wikihow directory is currently empty.
  5. Clear the screen. To clear the screen, use the cls command. Simply type cls and press enter to clear all of the contents of the screen. Only the command prompt will remain on the screen as shown above.
  6. Create a new file. In order to create a new file, use the type NUL > command. Type: type NUL> filename and press enter to create a new empty file. In the example above, type NUL> newfile was typed.
  7. Add another new file. Now repeat step 5 to create a second new file. Call this file newFile1. The new command is: type NUL> newFile1.
  8. Check directory contents. Now check the directory contents using the dir command. The wikihow directory now contains two new files called newFile and newFile1 as shown above.
  9. Delete files. To delete files, use the del command. Type del -> filename to delete a specific file. In this example, delete newFile using the following command: del newFile. Now, check the wikihow directory contents you can see that newFile has been deleted. Clear the screen using the cls command.
  10. Move into parent directory. In order to complete the next step, deleting a directory, first, leave the current working directory. To do this, use a version of the change directory command. Use the cd.. command to move into the parent directory without typing the directory name. In the example, type: cd.. as shown above. Notice the prompt is now back to C:\users\Brian> which means that this is no longer in the wikihow directory.
  11. Remove/delete an empty directory. To delete a directory, use the rmdir command. You can't be in the directory that you want to delete (see step 10 above). If the directory is empty, meaning it does not contain any files, you can delete it by simply typing rmdir -> directory name. In this example the wikihow directory still contains newFile1 so the rmdir command will not work in this case. If the directory is not empty you will receive an error message as shown above.
  12. Remove a directory that contains files. To remove a directory that contains files, use a modified version of the rmdir command. Use the rmdir /s command. In the example, type: rmdir /s wikihow and press the enter key. You will be prompted to confirm that you want to delete the directory by typing Y/N. Type Y for yes or N for no as shown above. When you type Y the entire directory and all of its contents are deleted from the system.

Tips

  • Commands can be in upper or lower case.
  • Use CLS command to clear the screen regularly. This makes your work more readable.

Warnings

  • Using the command prompt requires practice and users should be careful when moving and deleting files. There are no warnings or second chances when deleting files so it is important that you are certain that you are deleting the correct files to avoid the loss of important documents.

Things You'll Need

  • Computer running windows operating system
  • Keyboard

Related Articles

Sources and Citations