HomeHow ToHow to delete files and folders using Command Prompt

How to delete files and folders using Command Prompt

-

There are many instances when you may face issues while deleting files and folders in Windows Explorer, and using Command Prompt can help you delete anything easily and quickly.

You can simply go to Windows Explorer, select the file or folder and then hit the delete button to remove it from your computer. However, this method can sometimes take an eternity to remove a large number of files within a directory.

In that case, the command prompt can come in super handy. Plus, it can also help you tackle restrictions while deleting some restricted files (unwanted system and junk files).

Also read: How to download Windows 11 ISO file & do a clean installation

However, keep in mind that the command to delete a file is final. The deleted items won’t go to the recycle bin, and it is impossible to recover data after utilising these commands.

So, make sure you only erase those files which you genuinely want to remove from your computer.

How to delete a file using CMD

  1. Click the Start button.
  2. In the Search box, type ‘cmd’.
  3. Right-click on Command Prompt, and then click Run as administrator.
Run CMD as administrator

4. Now, type the filename with extension followed by its full path, which you want to delete. If you don’t know its extension, right-click on the file and select properties (it will show you its full path with name and file extension).

del d:\jun\screenshot.png

Or you can try force deleting a file when Windows locks it, and it says the file is in use by a program. Use the following command to remove a restricted file.

del /f filename

5. Here, ‘del’ is the delete command, ‘d:\jun\’ would be the path to my file, and ‘screenshot.png’ is the file I want to delete.

The same goes for the force deletion method. Just replace ‘filename’ with your actual filename without an apostrophe (‘). So, change it accordingly to the file that you want to delete.

6. Hit Enter after you put in the command, and the file should be deleted by now.

How to delete a folder using CMD

  1. Click the Start button.
  2. In the Search box, type ‘cmd’.
  3. Right-click on Command Prompt, and then click Run as administrator.
  4. Type the following command.
rd /s /q "folder path"

Replace the “folder path” with the actual path of the folder that you want to delete.

5. Hit Enter after you put in the command, and the folder should be deleted by now.

Example – rd /s /q “d:\jun” – here jun is the folder I want to delete.


Now you can delete anything on your computer using the Command prompt. However, keep in mind that any files or folders deleted using the command line are not recoverable. If you have any doubts, then make a backup first.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular