To recover files deleted by a virus, first remove the malware with a full antivirus scan, then check whether your files are really deleted or only hidden, which is very common on USB drives. Unhide hidden files with File Explorer's settings or the attrib command. For files that were truly deleted, scan the drive with recovery software and restore the files to a separate, clean drive. Ransomware is different: recovery software cannot decrypt files, so your options there are backups, older shadow copies and published decryption tools.
Here is the safe order to do things in, and what to expect for each kind of malware.
Step 1: Clean the PC first
Recovering files while malware is still active is a waste of effort. It can delete, hide or encrypt them again as soon as you restore them.
- Disconnect from the network if you suspect ransomware, to stop it spreading to shared drives and cloud folders.
- Unplug external drives you have not already lost files from, so they are not infected too.
- Run a full scan. Open Windows Security → Virus & threat protection → Scan options, choose Full scan and click Scan now.
- Run an offline scan if the infection is stubborn. Choose Microsoft Defender Antivirus (offline scan) in the same list. The PC restarts and scans before Windows loads.
- Scan USB drives as well, by right-clicking them in File Explorer and choosing to scan with Microsoft Defender.
If the antivirus quarantined a file you actually need, see how to restore a file deleted by Windows Defender.
Step 2: Work out what kind of loss it is
| What you see | Likely cause | What to do |
|---|---|---|
| USB drive shows only shortcuts, or looks empty but space is still used | Files hidden by a shortcut virus | Unhide with attrib |
| Folders gone, but drive properties show the same used space | Files hidden | Show hidden files, then attrib |
| Files gone and the space is now free | Files deleted | Recovery scan |
| Files renamed with a new extension, ransom note in folders | Ransomware encryption | Backups, shadow copies, decryptors |
| Drive shows as RAW or asks to be formatted | File system damaged | Recovery scan, do not format |
The quickest test: right-click the drive in File Explorer and choose Properties. If Used space is roughly what it was before your files vanished, they are probably hidden, not deleted.
Step 3: Unhide hidden files
Show hidden files in File Explorer
In Windows 11, click View → Show → Hidden items. In Windows 10, tick Hidden items on the View tab. To see files marked as protected system files too, open Folder Options, go to the View tab and clear Hide protected operating system files. Turn it back on when you are done.
Remove the hidden attributes with attrib
- Note the drive letter, for example
E:. - Open Command Prompt as administrator.
- Run
attrib -h -r -s /s /d E:\*.*, replacingE:with your drive letter.
This clears the hidden, read-only and system flags from every file and folder on the drive. Your folders should reappear. Delete any leftover shortcut files (.lnk) and unfamiliar .exe or script files in the root of the drive that you did not put there, after scanning with your antivirus. Our guide to a USB drive that shows empty but has data covers this in more detail.
Step 4: Recover files that were really deleted
When malware deletes files, it usually deletes them the normal way, so the data stays on the drive until it is overwritten, just like any other deletion. A recovery scan can often find it.
- Stop saving files to the affected drive.
- Scan the drive with Drive Restorer. A quick scan finds recently deleted files with their names and folders. A deep scan reads every sector and finds files by their content when the records are gone.
- Filter and preview the results. Check the recovery chance rating, because files deleted some time before you noticed may be partly overwritten.
- Restore to a separate, clean drive, never to the drive you are scanning.
- Scan the recovered files with your antivirus before opening them.
Drive Restorer is read-only on the source drive, so scanning does not make the situation worse. On a system SSD, deleted data may already have been cleared by TRIM, so act quickly.
When a virus damages the whole drive
Some malware goes further than deleting files: it can wipe the partition table or corrupt the file system, leaving a drive that shows as RAW, asks to be formatted or appears as unallocated space in Disk Management. Do not format or initialize it. These are logical problems that a partition search and deep scan can often work around, once the PC is clean. See how to recover a lost partition for the steps.
Ransomware: what recovery software can and cannot do
Ransomware encrypts your files and asks for payment for the key. Recovery software cannot decrypt them. What sometimes helps:
- Backups that were not connected at the time, such as an unplugged external drive or a cloud service with version history.
- OneDrive version history for individual files, and for Microsoft 365 subscribers, the option to restore the whole OneDrive to an earlier point in time from the web.
- Previous Versions, if shadow copies survived. Many ransomware strains delete them, but it is worth checking.
- Deleted originals. Some ransomware writes an encrypted copy and deletes the original. A recovery scan can sometimes find those originals, but often they have been overwritten or wiped.
- Published decryptors. Security companies and law enforcement publish free decryption tools for some ransomware families. Identify the strain from the ransom note and file extension, and search for a decryptor from a trusted security source.
Keep a copy of the encrypted files even if you cannot open them now. A decryptor for your strain may be released later.
Preventing the next one
- Keep Windows and your browser up to date, and keep Microsoft Defender or another antivirus running.
- Turn on Controlled folder access in Virus & threat protection → Ransomware protection to stop untrusted apps changing your files.
- Do not open unexpected attachments or run programs from USB drives you do not trust.
- Keep at least one backup that is not permanently connected to the PC.
For other common causes of vanishing files, see files disappeared from the desktop.
Frequently asked questions
Should I remove the virus before recovering files?
Yes. Scan and clean the PC first, otherwise the malware can delete or encrypt the recovered files again. Save recovered files to a separate drive.
Can recovery software decrypt ransomware files?
No. Recovery software cannot decrypt files. In some cases it can find deleted original copies, but often they have been overwritten.
Are my files deleted or just hidden?
Many viruses only hide files. If the drive's used space has not changed, show hidden files or use attrib before trying recovery.
