How to Repair a SanDisk USB Flash Drive with CMD

An unreadable SanDisk USB drive is usually fixable, and your files are usually recoverable. The order matters: recover your data first, then repair the drive. Here's how, with free CMD commands.

Fact-checked Reviewed by Meera Krishnan Updated June 18, 2026 Based on 4 sources

Key takeaways

  • Recover your data first, repair the drive second. Repairing erases everything, so order is critical.
  • If files are hidden by a virus, the attrib command brings them back, no software needed.
  • chkdsk can fix file system errors that make a drive unreadable, after you've saved your files.
  • For real corruption, free signature-scanning software copies files off the raw drive.
  • Only run diskpart clean and format to revive the drive once your data is safe. It wipes everything.

You plug in your SanDisk USB drive and Windows can't read it. Maybe it asks you to format it, maybe it shows nothing at all. If that drive holds something important, the order of what you do next really matters.

Most "repair" guides get this dangerously backwards. They walk you through formatting the drive to fix it, which works for the drive but destroys your files. So here's the rule this guide follows: get your data off first, then repair the drive. Recovery and repair are two separate jobs, and doing them in the wrong order is how people lose their thesis.

Summary

Recover your data first, then repair the drive. Try the attrib command to unhide files, then free recovery software to copy your data off. Once your files are safe, run chkdsk to fix file system errors, or use diskpart clean and format to fully revive the drive. Never format before your data is recovered, because formatting erases everything.

Don't format or run diskpart until your data is recovered

Formatting and diskpart clean are repair steps, not recovery steps. They wipe the drive. If Windows pops up a "You need to format the disk" message, click Cancel. Work through the recovery section below first. Only move to the repair section once your files are copied somewhere safe, or you're sure there's nothing worth saving.

Part 1: Recover your data first

Before touching anything that writes to the drive, get your files off. Two routes, easiest first.

Unhide files with the attrib command

A common cause of a "blank" SanDisk drive is a virus that flips your files to hidden. They're still there. The attrib command reveals them, and it doesn't write over your data. Plug in the drive, note its letter (say F:), open Command Prompt as administrator and run:

Command Prompt (Admin)
:: Replace F: with your USB drive's letter

:: Clear hidden, read-only and system flags on every file
attrib -h -r -s /s /d F:\*.*
The switches: -h clears hidden, -r read-only, -s system, /s and /d apply through every subfolder.

Open the drive afterward. Your files often reappear, sometimes inside a folder with no name. Copy anything you need to your computer right away. If the files show up, you may not need recovery software at all.

Copy files off with free recovery software

If attrib doesn't reveal your files, or the drive is genuinely corrupted, use signature-based recovery. These tools read the raw drive and rebuild files by their signatures, without relying on the broken file system. Free, trusted options are PhotoRec (open source) and Recuva (Windows).

Recover files to your computer or another drive, never back onto the SanDisk drive you're rescuing.

Run a deep scan on the USB drive, preview what it finds, and save everything you care about to a safe location. Once your data is copied off and verified, and only then, move on to repairing the drive.

Part 2: Repair the drive once your data is safe

With your files recovered, you can fix the drive itself. Start with the gentlest option.

Fix file system errors with chkdsk

chkdsk repairs the kind of file system corruption that makes a drive unreadable. Run it on your USB drive letter:

Command Prompt (Admin)
:: Replace F: with your USB drive's letter
chkdsk F: /f

:: /f fixes file system errors. Add /r to also check for bad sectors:
chkdsk F: /f /r
Run chkdsk after recovery, not before. On a badly corrupted drive it can occasionally make raw recovery harder.

If chkdsk brings the drive back and your files are intact, you're done. If the drive is still unreadable, it needs a full rebuild.

Rebuild the drive with diskpart and format

This is the heavy option. It wipes the drive completely and gives it a fresh, clean file system. Do this only after your data is recovered. Type each line carefully, especially select disk, because choosing the wrong disk number can wipe the wrong drive.

Command Prompt (Admin)
diskpart
list disk            :: find your USB by its size
select disk 2        :: use YOUR USB's number, not necessarily 2
clean                :: wipes the partition table
create partition primary
format fs=fat32 quick   :: use ntfs for files over 4 GB
assign               :: give it a drive letter
exit
Double-check the disk number with list disk before running clean. The wrong number wipes the wrong drive.

After this the drive is blank and working again, ready to reuse. Your recovered files are safe on your computer where you copied them.

Repair without CMD

Prefer a graphical route? Open This PC, right-click the USB drive, choose Properties, open the Tools tab and click Check under error checking. Windows scans and fixes file system problems. To fully reset the drive instead, right-click it and choose Format, but again, only after your data is recovered.

How to stop USB corruption happening again

SanDisk and other USB drives mostly get corrupted from a handful of avoidable habits. Always use Safely Remove Hardware before unplugging, since yanking a drive mid-write is the top cause of corruption. Scan drives for malware before opening them on a shared computer, disable autorun to block infected drives from running code, and don't fill a drive to its absolute limit. Most importantly, keep a second copy of anything that matters, because a USB stick is transport, not a safe long-term home.

Drive fixed and files recovered? Copy those files to a permanent location now, then reuse the drive with a little more confidence. What was on it that you'd want protected next time?

Frequently asked questions

Should I recover data or repair the drive first?

Always recover your data first. Repairing a USB drive with diskpart or format erases everything on it. If your files matter, copy them off with recovery software before you run any repair command. Only repair the drive once your data is safe or you're certain there's nothing to save.

Will chkdsk fix an unreadable SanDisk USB drive?

Sometimes. chkdsk can fix file system errors that make a drive unreadable, and the attrib command can unhide files a virus has hidden. But chkdsk can occasionally make recovery harder on a badly corrupted drive, so recover your important files first, then run chkdsk.

Does diskpart clean delete all my data?

Yes. diskpart clean followed by a format wipes the drive's partition table and prepares a fresh file system. It does not recover data, it removes it. Only use it to repair a drive after you've already saved anything you need.

Why is my SanDisk USB drive unreadable?

Common causes are file system corruption from unsafe removal, a virus that hides or damages files, a worn-out flash controller, or physical damage. Software can fix the first two. A failed controller or physical damage usually needs professional help.

Can I recover files from a USB drive that asks to be formatted?

Yes. The format prompt means the file system is damaged, not that the data is gone. Click Cancel, then run free signature-scanning software like PhotoRec to pull files off the raw drive before you repair or format it.

How do I stop my USB drive getting corrupted again?

Always use Safely Remove Hardware before unplugging, scan the drive for malware, avoid filling it completely, and keep a second copy of anything important. Treat a USB stick as transport, not as the only home for valuable files.

Sources & references

This guide was written from hands-on testing and cross-checked against the following references.

  1. Microsoft Learn: chkdsk command reference. learn.microsoft.com
  2. Microsoft Learn: diskpart command reference. learn.microsoft.com
  3. Microsoft Learn: attrib command reference. learn.microsoft.com
  4. Internal lab testing: USB flash drive repair and recovery, TechNewsKB, 2024 to 2026.
Comments (3) Moderated
A
Aditya M. · 2 days ago

Thank you for putting recovery before repair. Every other guide had me running diskpart first. I'd have wiped my dissertation.

↑ Helpful (24)Reply
C
Clara B. · 5 days ago

attrib command revealed everything. A virus had hidden my files and the drive looked empty. Two minutes and all back.

↑ Helpful (14)Reply
T
Tomas K. · 1 week ago

After recovery, the diskpart format brought my dead SanDisk fully back to life. Clear warning about the disk number saved me too.

↑ Helpful (8)Reply