How to Create and Delete Files and Directories from Windows Command Prompt

Open the Windows Command Prompt., Create a new directory., Change the current working directory., Check the directory contents., Clear the screen., Create a new file., Add another new file., Check directory contents., Delete files., Move into parent...

12 Steps 3 min read Advanced

Step-by-Step Guide

  1. Step 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. Step 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 LifeGuide Hub was created by typing: mkdir LifeGuide Hub. , 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 LifeGuide Hub was typed.

    Now the prompt looks like this:
    C:\users\Brian\LifeGuide Hub> as shown above. , 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 LifeGuide Hub directory is currently empty. , 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. , 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. , Now repeat step 5 to create a second new file.

    Call this file newFile1.

    The new command is: type NUL> newFile1. , Now check the directory contents using the dir command.

    The LifeGuide Hub directory now contains two new files called newFile and newFile1 as shown above. , 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 LifeGuide Hub directory contents you can see that newFile has been deleted.

    Clear the screen using the cls command. , 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 LifeGuide Hub 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 LifeGuide Hub 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. , 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 LifeGuide Hub 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.
  3. Step 3: Change the current working directory.

  4. Step 4: Check the directory contents.

  5. Step 5: Clear the screen.

  6. Step 6: Create a new file.

  7. Step 7: Add another new file.

  8. Step 8: Check directory contents.

  9. Step 9: Delete files.

  10. Step 10: Move into parent directory.

  11. Step 11: Remove/delete an empty directory.

  12. Step 12: Remove a directory that contains files.

Detailed Guide

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>.

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 LifeGuide Hub was created by typing: mkdir LifeGuide Hub. , 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 LifeGuide Hub was typed.

Now the prompt looks like this:
C:\users\Brian\LifeGuide Hub> as shown above. , 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 LifeGuide Hub directory is currently empty. , 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. , 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. , Now repeat step 5 to create a second new file.

Call this file newFile1.

The new command is: type NUL> newFile1. , Now check the directory contents using the dir command.

The LifeGuide Hub directory now contains two new files called newFile and newFile1 as shown above. , 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 LifeGuide Hub directory contents you can see that newFile has been deleted.

Clear the screen using the cls command. , 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 LifeGuide Hub 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 LifeGuide Hub 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. , 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 LifeGuide Hub 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.

About the Author

K

Kyle Shaw

Brings years of experience writing about organization and related subjects.

108 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: