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.

Advertisement
  • zaetzeatez

    This reminds me of when I decided I wanted all thumbs.db files deleted from my computer.

    So I opened CMD and entered this under C:\

    del /s /q /f /a:h Thumbs.db

    And that did it. Beware though. Sometimes, Thumbs.db file isn’t hidden. So you have to do it again without the /a:h switch.

    You can also do this with .DS_STORE files

  • Pingback: Delete Infected And Locked Files With Remove With Batch

  • thor

    just use linux on usb. boot on usb and delete. what you want

  • Anonymous

    It’s still said “Access is Denied”

  • stupid

    I find it so stupid when I’m the owner of my computer and the administrator but still says access is denied. wtf should I be in this computer rather than administrator? a god?!! to have access in deleting a folder that is useless to me?!

  • http://www.onrupee.com/ Raj

    I am getting the following error “The process cannot access the file because it is being us
    ed by another process.” what should be the case now?

  • Richie

    Thank you, the second command worked for me :)

  • FAILED

    tried these, says access denied. i have 4 ‘empty’ folders (but they take space up) andcant delete cause it says they are open in another program.. when i go in the folder nothing is there! tried ‘unlockers’ file assassin.. cmd prompts.. still cant get rid of them.. only rename and move them..

  • Arthamus

    what if it says the file does not exist, but it does, what do i do then?

  • Chris Dalley

    If it doesn’t work make sure to run CMD “as administrator”