Following a computer virus attack, files and/or folders may become lost, even from USBs, external hard drives and computers. However, this does not always equate to files being erased.
Whilst some computer viruses conceal files, other strains will either erase and/or scramble files.
To maximise the likelihood of file recovery, first isolate the infected computer and do not add further information to the storage device in question. Additional information may overwrite lost files.
Method 1 – Unhiding Files with the ATTRIB Command
Some computer viruses disguise genuine folders and substitute them with harmful shortcuts.
Windows’ Command Prompt can be used to unhide files.
1. Press the Start button and type in cmd.
2. Right-click on Command Prompt and choose ‘Run as administrator’.
3. Locate the drive letter of the infected device by looking at File Explorer.
4. Type in the following:
attrib -h -r -s /s /d E:\.
Note: Replace E: with the correct drive letter for your infected USB or external device.
Function Explanation
| Parameter | Function |
|---|---|
-h | Removes the Hidden attribute |
-r | Removes the Read-only attribute |
-s | Removes the System attribute |
/s | Processes files in subdirectories |
/d | Includes directories |
Following entry of the above command, view the drive in File Explorer to see if your original files are visible.
Never apply this command to your Windows’ main drive as it alters the settings of genuine system files.
Whilst the ATTRIB command unhides files, it is unable to recover files which have actually been erased and does not also uninstall computer viruses.
Method 2 – Investigating for Remaining Files
Even prior to unhiding, the dir command can be used in CMD to investigate if concealed files still exist on the infected device.
Type in:
dir E:\ /a /s
The /a switch enables viewing of files irrespective of their settings. The /s switch allows subordinate folders to be analysed.
Should your lost files be shown then they may not have in fact been erased. Should they not be shown then it would be advisable to utilize file recovery software.
Method 3 – Recovering Erased Files with Windows File Recovery
Conversely to the ATTRIB command, Windows File Recovery seeks to recover information which has been erased from storage devices.
Download the free Windows File Recovery command line file recovery software from the Microsoft Store.
Where the infected device includes your Windows operating system, do not install file recovery software onto it. Ideally, attach the infected device as a further drive to another uncontaminated computer.
Windows File Recovery can carry out both standard and in-depth analyses:
Standard – Appropriate for recently erased files from well-functioning NTFS drives.
In-depth – Advisable for older erasures, re-formatted drives and FAT/exFAT file systems.
To recover lost PDF and Word files from drive E: and store them on drive D:, input:
winfr E: D: /extensive /n .pdf /n .docx
To recover recently erased image files from an NTFS drive:
winfr E: D: /regular /n .jpg /n .png
Press Y to confirm the recovery process.
Windows File Recovery generates a folder for the recovered files on the target drive.
Always recover files to an external physical storage device to prevent overwriting.
Method 4 – Eliminating the Computer Virus to Regain Full Device Functionality
File recovery does not uninstall the computer virus which led to files becoming lost.
On a clean or isolated Windows computer, go to Windows Security > Virus & threat protection > Scan options.
Carry out a full system scan or, if you believe there may still be computer viruses present, run Microsoft Defender Offline.
Prior to opening recovered files, especially those of the executable, script or questionable shortcut types, scan them.
Unless you are sure of their authenticity, do not un-quarantine files.
Can CMD Recover Files that have been Scrambled by Ransomware?
Neither the ATTRIB command nor Windows File Recovery can directly descramble files scrambled by ransomware.
Depending on which strain of ransomware has been used, it may be possible to recover files using good quality backup copies and/or particular descrambling software.
Free descrambling software is available for some recognized strains of ransomware via the ‘No More Ransom’ site.
Hold on to scrambled files until you are sure that suitable descrambling software is available.
Common Recovery Errors to Avoid
Do not re-format the infected device, or too early execute disk repair processes such as chkdsk /f. Nor should you install superfluous software on the infected device.
All of these actions can affect the infected storage medium and hinder file recovery.
Whether or not file recovery is successful will depend on whether the initial information can still be physically accessed. Information may be irretrievable by standard recovery software if it has been overwritten or if TRIM has been applied to data held on an SSD.
For crucial business and personal files such as photographs, it may be wise to consult professional file recovery services, rather than attempting potentially damaging DIY recovery methods.









