1. Home
  2. Windows

How to Delete An Infected File Or Folder From Command Prompt

There are more protection software available than there ever were before. That is because both virus and malware threats are increasing as compared to a decade back. Despite the use of several protection software there is no guarantee that a malicious source can be stopped from infecting your system. Many a times virus and trojans can restrict access to data on the system and continue to corrupt other files. In such a case the infected files might become inaccessible due to their infected state. In this post we will tell you how to get rid of these files and folders from the command prompt, which can be particularly useful if one is being unable to delete these files from Windows Explorer or using 3rd party tools.

To get started open command prompt from the Start menu (go to Run and type cmd or from Start-> Accessories –> Command Prompt). Enter the command line:

DEL /F /Q /A C:\Users\UserName\Desktop\file name

Enter Del (for delete) followed by /F (for force deleting), /Q (for quiet mode, which does not prompt any confirmations before deletion), /A (allows file with set attributes (ex: hidden files, read-only files, etc to be deleted), C (drive) followed by the users directory, username, location (e.g. desktop) and file name. For the novelty of it, I named the file as “infected”. So the required command became as:

DEL /F /Q /A C:\Users\farshad\Desktop\infected.docx

Where docx = the document extension.

Infected file

Similarly, to delete folders from a directory use the following command line:

RD /S /Q C:\File path (e.g. Users\username\Desktop\Folder)

So the command line in this case became:

RD /S /Q C:\Users\farshad\Desktop\Folder

RD (remove directory), S (deletes all files and subfolders), Q (does not prompt for confirmation), C (Drive name), followed by folder path.

Infected Folder

The same method can also be used to remove general files and folders, however, the option to remove files forcefully can greatly help in getting rid of infected data on your system.

Leave a comment