July 18, 2019

Delete a Folder or File using Command Prompt (CMD)

Delete a Folder or File using Command Prompt: To create or delete a folder on your device you can simply right-click on the desktop and choose the desired options. Isn’t it easy? Yes, it is a very easy process but sometimes this method doesn’t work, or you can face some problems. So that’s why you don’t need to rely on one single method. You can always use the Command Prompt (CMD) to create a new folder or file and delete folders or files. In this guide, we will discuss all the possible methods to create or delete files & folders. 

If you are not able to delete some files or folders and you see a Windows warning message then don’t worry, you can easily delete such folders or files using the Command Prompt. Therefore, learning to use Command Prompt to perform certain tasks is always helpful. We will discuss all the ways via which Microsoft users can create & delete files or folders.

Delete a Folder or File using Command Prompt

Note: If you delete a folder, then it will also delete all its contents & files. Therefore, you need to keep this in mind that once you delete a folder using Command Prompt, you will delete all the files present within the selected folder.

Delete Key

One of the easiest ways to delete a folder or file is to select the particular folder or file and then press the Delete button your keypad. You just need to locate the particular file or folder on your device. If you want to delete multiple files & folders then you need to press & hold the Ctrl key and select all the files or folders which you need to delete. Once done, then again press the Delete button on your keyboard.

Delete folders or files with right-click option 

You can select the file or folder that you want to delete and right-click on that file or folder and choose the delete option from the right-click context menu.

Right click on that file or folder and select delete option from the pop-up menu

How to Delete a Folder or File using Command Prompt

Make sure to create a restore point just in case something goes wrong.

While deleting, creating, or opening any file or folder using the Command Prompt, you need to make sure that you use the right command to get your task done. Hopefully, you will find all the below-mentioned methods helpful.

Method 1: How to delete files or folders in MS-DOS Command Prompt

Note: You need to open a Command prompt or Windows PowerShell with admin access on your device. 

1.Open Elevated Command Prompt using any one of the methods mentioned here.

2.Now type the following command into the Command Prompt and hit Enter:

Del example.txt

To delete files in MS-DOS command prompt type the command

3.You need to enter the full path (location) of the file and file name with its extension to delete that file.

For example, I deleted sample.docx file from my device. To delete I entered “del sample.docx” without quotation marks.  But first, I need to navigate to the said file location using the cd command.

How to delete a folder or directory using the Command Prompt

1.Again open Elevated Command Prompt using any one of the methods mentioned here.

2.Now you need to enter the below-mentioned command into cmd and hit Enter: 

rmdir /s <complete path of folder>

3.If your folder path has spaces, then you need to use quotation marks for the path. 

rmdir /s “C:UserssurajDesktoptest folder”

4.Let’s take an example for illustration purpose: I have created a test folder in my D drive. To delete that folder I need to enter the below command:

rmdir /s d: testfolder

To delete the folder type the command in the command prompt

You need to type the drive name where your folder is saved and then type the name of the said folder. Once you type the above command and hit Enter, your folder and all of its content will be deleted permanently from your PC without leaving any trace on your device.

Now that you have learned how to delete a folder or file using Command Prompt (CMD), do you wish to continue to learn more thing that you can do with the Command Prompt?  Well, if you are interested then in the next part we will talk about how to create a folder, open any folder and file using the Command Prompt. 

Method 2: How to create a Folder using the Command Prompt

1.Open Elevated Command Prompt using any one of the methods mentioned here.

2.Now type the following command into the Command Prompt and hit Enter:

MD drive_letterfolder name

Note: Here you need to replace drive_letter with the actual drive letter where you want to create the said folder. And also, you need to replace the folder name with the actual name of the folder which you wish to use.

To create the folder type the command in the command prompt

3.In the above example, I have created a testfolder in the D: drive of my PC and for that, I have used the command:

MD D: testfolder

Here you can change the drive and folder name according to your drive preferences and folder name. Now you can check whether the command successfully executed or not by going to the drive where you have created the folder. As in my case, I have created the folder in the D: drive. Below image shows that the folder is created under D: drive on my system.

Folder is created under d drive on the system

If you want to open a particular folder on your device, you can do it using the Command Prompt as well.

1.Open the Command Prompt and type the below-given command in the cmd:

start drive_name: folder name

Note: Here you need to replace drive_letter with the actual drive letter where your folder which you wish to open reside. And also, you need to replace the folder name with the actual name of the folder which you wish to use.

2.In the above example, I have opened the same folder (testfolder) that I created in the above step and for that, I have used the command:

start D: testfolder

To open the created folder type the command in the command prompt

Once you will hit the enter button, the folder will immediately open on your screen without a delay. Hurray!

Open the folder on your screen without a delay

Delete a folder with the Command Prompt

Although we have already discussed how to delete a folder with Command Prompt but in this method, we will use another command. This command is also equally useful to delete a folder on your device.

1.Open Elevated Command Prompt using any one of the methods mentioned here.

2.Now type the following command into the Command Prompt and hit Enter:

Rd drive_name: folder name

3.For example, I deleted the same folder which we created above, testfolder. For that, I use the following command:

Rd D: testfolder

deleted the same folder that created type the command in the command prompt

Once you hit Enter, the above folder (testfolder) will be deleted immediately from your system. This folder will be permanently deleted from your system and cannot be recovered. Once deleted, you will not find it in the Recycle bin to restore. Therefore, you need to be sure while deleting any files or folders with Command Prompt as you won’t be able to recover the data once deleted.

Recommended:

I hope this article was helpful and now you can easily Delete a Folder or File using Command Prompt (CMD), but if you still have any questions regarding this tutorial then feel free to ask them in the comment’s section.