How to 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. We will be creating a new directory or folder and working within that directory to create and delete files. We will finish by deleting the directory itself. After completing this article you should be more comfortable with using the Command Prompt for basic tasks. Ok, let’s get right into working with the Windows Command Line with step 1 below!

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

Create a new directory. We will use the mkdir command to create a new directory to work with. The command is mkdir -> directory name. In the example above we created a new directory called wikihow by typing: .

Change the current working directory. In order to move into the newly created directory we will use the cd or change directory command. The command is cd -> directory name. In our example we typed . Now our prompt looks like this as shown above.

Check directory contents. In order to check the contents of the current directory we can use the dir command. Simply type and press enter and a list of the directory contents will be displayed as shown. In our example the wikihow directory is currently empty.

Clear the screen. To clear the screen we will use the cls command. Simply type and press enter to clear all of the contents of the screen. Only the command prompt will remain on the screen as shown above.

Create a new file. In order to create a new file we will use the type NUL > command. Type: type NUL> filename and press enter to create a new empty file. In our example above we typed the following to create a new file: type .

Add another new file. Now we will repeat step 5 to create a second newfile. We will call this file newFile1. So our new command is: type .

Check directory contents. Now we will check the directory contents usingthe dir command. The wikihow directory now contains two new files called, newFile and newFile1 as shown above.

Delete files. To delete files we can use the del command. Type del -> filename to delete a specific file. In our example we will delete newFile using the following command: . Now if we check the wikihow directory contents you can see that newFile has been deleted. Clear the screen using cls command.

Move into parent directory. In order to complete our next step, deleting a directory, we must first leave the current working directory. To do this we will use a version of the change directory command. We can use cd.. command to move into the parent directory without typing the directory name. In our example we will type: as shown above. Notice the prompt is now back to C:\users\Brian> which means we are no longer in the wikihow directory.

Remove/delete an empty directory. To delete a directory we will 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 . In our 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.

Remove a directory that contains files. To remove a directory that contains files we must use a modified version of the rmdir command. We will use the rmdir /s command. In our example we will type: and press enter. We will be prompted to confirm that we want to delete the directory by typing Y/N. Type for yes or for no as shown above. When you type Y the entire directory and all of its contents are deleted from the system.

Commands can be in upper or lower case.

Use CLS command to clear the screen regularly. This makes your work more readable.

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


Related wikiHows
How to Delete a File Using Command Prompt

How to Change Directories in Command Prompt

How to Copy Files in Command Prompt

Sources and Citations

Link: Company:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s