Recover your files before you repair a USB flash drive because repair commands can erase data. Enter attrib to clear the Hidden attribute and copy your files off. Use chkdsk to fix file system errors after your files are safe. Use diskpart clean as the last step because it makes the old partitions inaccessible. Check the disk number twice before you confirm it.
You plug in your SanDisk USB flash drive and Windows can't open it. Windows asks you to format the stick or shows nothing at all.
Most repair guides start with formatting. Formatting fixes the stick but destroys your files. This guide recovers data first and repairs second. Lost files from a working flash drive are covered in how to recover deleted files from a flash drive.
Should You Recover Data or Repair a USB Drive First?
Recover first. Repair commands alter the disk and one of them erases it.
| Command | Purpose | Risk to Your Files |
|---|---|---|
| attrib | Clears file attributes such as Hidden | Low. Changes attributes only |
| chkdsk | Fixes file system errors | Medium. Microsoft warns that FAT repairs alter the file allocation table |
| diskpart clean | Removes all partition and volume formatting | High. Old partitions and data become inaccessible |
Select Cancel if Windows asks you to format the stick. That prompt doesn't mean your data is gone.
How do You Unhide Files With attrib?
Microsoft documents attrib as the command that sets or clears file attributes. Use -h for Hidden, -r for the read only attribute and -s for System. Add /s to apply the change in every subfolder and /d to apply it to directories. See Microsoft attrib reference.
- Plug in the USB drive and note its letter in File Explorer.
- Open Command Prompt.
- Enter the command below with your own drive letter instead of F.
:: Replace F: with your USB drive letter
attrib -h -r -s /s /d F:\*.*
Open the stick afterward and copy any files that appear to your computer. If your files are back you can skip recovery software.
How do You Copy Files Off a Corrupted USB Drive?
Signature based recovery software rebuilds files without a working file system. PhotoRec is a free, open source option. Its documentation states that it ignores the file system and recognizes more than 480 file extensions.
- Connect the USB drive to a computer.
- Scan the drive with the recovery software.
- Save recovered files to your computer. PhotoRec documentation advises against writing them to the partition they came from.
- Open the recovered files and confirm that they work.
How do You Fix File System Errors With chkdsk?
Microsoft states that /f fixes logical errors and that /r locates bad sectors and recovers readable information. Switch /r includes /f. Both need an elevated Command Prompt. See Microsoft chkdsk reference.
:: Replace F: with your USB drive letter
chkdsk F: /f
:: Add /r to check for bad sectors
chkdsk F: /f /r
On FAT file systems Microsoft warns that repairs alter the file allocation table and can lose data. Lost chains save as File followed by a number with the .chk extension when you answer Y. Recover your files before this step.
How do You Rebuild a USB Drive With diskpart?
Microsoft states that diskpart clean removes all partition and volume formatting from the disk with focus. Confirm the correct disk first because clean is destructive. See Microsoft diskpart reference.
diskpart
list disk
:: Find your USB drive by its size
select disk 2
:: Use the number of your USB drive, not necessarily 2
clean
create partition primary
format fs=ntfs quick
assign
exit
- Check the disk number. Microsoft states that focus stays on the selected disk for later commands.
- Check the size. Disk numbers can change when hardware is added or removed.
- Save your files first. Old data becomes inaccessible after clean.
Microsoft's example formats with fs=ntfs. Assign gives the volume a drive letter so it shows in File Explorer.
How do You Avoid USB Corruption?
Microsoft advises that you always safely remove USB flash drives to avoid data loss. Right click the Safely Remove Hardware and Eject Media icon in the taskbar and select Eject followed by your device name. Unplug the drive after the Safe To Remove Hardware notice. See Microsoft guide to safely removing hardware.
Store a second copy of important files on another disk or in cloud storage.
Frequently Asked Questions
Should I Recover Data or Repair the USB Drive First?
Recover your data first. Diskpart clean makes old partitions inaccessible and chkdsk repairs on FAT file systems can lose data.
Will chkdsk Fix an Unreadable SanDisk USB Drive?
It fixes logical file system errors when Windows can lock the disk. Microsoft warns about FAT repairs so copy your files first.
Does diskpart Clean Delete All My Data?
Yes. Clean wipes the partition layout of the selected disk and the old data becomes inaccessible.
How do I Unhide Files on a USB Drive?
Enter attrib -h -r -s /s /d followed by your drive letter and the *.* pattern. Switch -h clears the Hidden attribute.
Can I Recover Files From a USB Drive That Asks for Formatting?
Yes. Select Cancel and scan the drive with signature based software. Save recovered files to a different disk.
How do I Remove a USB Drive Safely?
Right click the Safely Remove Hardware and Eject Media icon in the taskbar and select Eject followed by your device name. Unplug the drive after the Safe To Remove Hardware notice.
Key Takeaways
- Recover your files before you repair a USB flash drive.
- Attrib clears the Hidden attribute and nothing else.
- Microsoft warns that chkdsk repairs on FAT can lose data.
- Diskpart clean makes old partitions and their data inaccessible.
- Eject a USB drive through Safely Remove Hardware before you unplug it.
Sources and References
This guide follows Microsoft documentation. PhotoRec details come from its official documentation.
- attrib (Microsoft Learn) learn.microsoft.com
- chkdsk (Microsoft Learn) learn.microsoft.com
- diskpart (Microsoft Learn) learn.microsoft.com
- Safely Remove Hardware in Windows (Microsoft Support) support.microsoft.com