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.


  1. hey thousand thanks.. its work . just need to boot in command prompt. safemode not secure enough for those hardest mallware

  2. Hi

    the folder I am trying to delete is in my MUSIC folder and is called “Drum & Bass”

    When I try any of the methods of using CMD to delete this folder (containing a WAV file that will not delete or be moved).. I get a message saying :

    “bass is not recognised as an internal or external command, operable program or batch file”

    I am at my wits end.. I need this folder (well, the file contained within) to be removed from my computer.

    Please can someone help?


    • Yes man, Move all the files away to a temp folder, small batches at a time. One of those batches won’t want to move. It’ll just load the prompt endlessly.
      On you’ve narrowed down the file, and everything else is in a temp folder.
      Reboot your computer, NUKE the folder containing the corrupted file. Voila.

      A reboot is needed as once the file is shown on screen, it confuses ur cpu and may not be able to be deleted.

      Oddly enough, both times this has happened to me in the last years, it’s been a Rihanna song.
      … weird.

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

  4. 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?

  5. 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?!

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.