
Tip: Before fixing corrupted USB flash drive using Command Prompt (CMD), you can use data recovery software - such as Donemax Data Recovery to recover or export all files from the drive to your computer. This data recovery tool also can help you easily repair a damaged USB flash drive or reformat a RAW USB flash drive.
PAGE CONTENT:
- Symptoms of a Corrupted USB Flash Drive
- Preparations Before Using CMD
- Steps to Use CHKDSK to Fix the Corrupted USB Drive
- Steps to Use Diskpart to Clean and Format the USB Drive
- Steps to Use ATTRIB Command to Remove Hidden or Read-Only Attributes
- What to Do If CMD Methods Don't Work?
- Tips to Prevent USB Drive Corruption
- Conclusion
USB flash drives are among the most convenient and widely used portable storage devices. From transferring files between computers to backing up important documents, their utility is unmatched. However, they are not immune to problems. Over time, a USB flash drive may become corrupted due to improper removal, file system errors, malware infections, or other issues. Fortunately, Windows provides a built-in solution through Command Prompt (CMD) that allows users to diagnose and repair many of these problems without installing third-party software.
This article offers a comprehensive, step-by-step guide to fixing a corrupted USB flash drive using CMD.
Symptoms of a Corrupted USB Flash Drive
Before diving into CMD commands, it's important to confirm that your USB flash drive is actually corrupted. Here are some common signs:
- USB drive not recognized by the computer: When plugged in, the drive does not show up in File Explorer or appears with an incorrect drive letter.
- Error messages like "You need to format the disk in drive X: before you can use it".
- Files and folders are missing or not accessible.
- The file system shows as RAW in Disk Management.
- The drive shows incorrect storage size or fails to display capacity.
If you are encountering any of these issues, your USB drive may be corrupted and needs fixing.
Preparations Before Using CMD
1. Backup Important Data (If Possible)
If your USB drive is still partially accessible, try to copy important files to another location before performing any repairs. Some CMD commands may result in data loss if not handled properly.
If you can't access the files stored on the USB flash drive, you can use data recovery program - such as Donemax Data Recovery to help recover and export all files from the drive to your computer's local disk.
Step 1. Download and install Donemax Data Recovery - a powerful data recovery program on your computer.
Step 2. Open Donemax Data Recovery and choose the USB flash drive to start data recovery.
Step 3. Click on Scan button to deeply scan the USB flash drive and find all existing files, inaccessible files, deleted/formatted/lost files, etc.
Step 4. After deep scan, you can preview all recoverable files. Then select the wanted files, click on Recover button. Don't save the recovered files to the USB flash drive, save the files to another drive.
2. Ensure the Drive is Properly Connected
Make sure the USB is securely connected to a functional USB port. Avoid using USB hubs during repairs.
3. Open CMD as Administrator
To access the required commands: Press Windows + S, type cmd, and then choose Run as administrator from the Command Prompt menu.
This opens CMD with elevated permissions, allowing you to execute system-level tasks.
Steps to Use CHKDSK to Fix the Corrupted USB Drive
The CHKDSK (Check Disk) command is one of the simplest and most effective methods for fixing file system errors.
How to Use CHKDSK
- Open Command Prompt (Admin).
- Type the below command and press Enter:
chkdsk X: /f
Replace X: with the actual drive letter of your USB flash drive.
Explanation of Parameters
- /f: Tells CHKDSK to fix any errors it finds.
What Happens Next?
- CMD will begin scanning the drive.
- If it detects file system errors, it will attempt to correct them.
- Once complete, a report will be displayed showing details about repairs.
When CHKDSK Fails
If CHKDSK returns a message like "CHKDSK is not available for RAW drives," it means the file system is unreadable, and you’ll need to use other commands such as Diskpart.
Steps to Use Diskpart to Clean and Format the USB Drive
When CHKDSK doesn't work, Diskpart can be used to clean and reformat the USB drive. Note: This process will erase all data on the drive.
Step-by-Step Guide to Clean and Format with Diskpart
Step 1: Launch Diskpart
- Launch Command Prompt in Administrator mode.
- Type the below command and press Enter:
diskpart
This opens the Diskpart shell.
Step 2: List All Disks
To identify the USB drive:
list disk
This will display all storage devices connected to your system, including internal hard drives and external USBs.
đź’ˇ Tip: Identify your USB drive by its size. For example, if your USB flash drive is 16 GB, it will likely show as Disk 1 or Disk 2 with size 14-16 GB.
Step 3: Select the USB Drive
Use the following command, replacing X with the correct disk number:
select disk X
Example:
select disk 1
Diskpart will confirm:
Disk 1 is now the selected disk.
Step 4: Clean the Disk
To erase all partitions and data:
clean
This command wipes the partition table and prepares the disk for reinitialization.
You will see:
DiskPart succeeded in cleaning the disk.
Step 5: Create a Primary Partition
Once cleaned, the disk has no partitions. Create a new one:
create partition primary
This tells Diskpart to set up a primary partition that can be formatted and used.
Step 6: Format the Partition
Now format the new partition with your desired file system:
format fs=ntfs quick
Or, if you prefer FAT32 (for compatibility with more devices like game consoles or Mac):
format fs=fat32 quick
The quick option speeds up the format. Without it, formatting can take much longer—especially for larger drives.
Step 7: Assign a Drive Letter
Make the USB usable in Windows:
assign
This gives the partition a drive letter (e.g., E:, F:) so it becomes accessible in File Explorer.
Step 8: Exit Diskpart
Once complete:
Exit
What If Diskpart Fails?
Sometimes, Diskpart may report errors such as:
- "The media is write protected"
- "DiskPart has encountered an error: Access is denied"
In such cases, try the following:
- Use the attributes disk clear readonly command after selecting the disk to remove write protection.
- Ensure the USB drive is not physically locked (some have a write-protect switch).
- Run CMD again as administrator.
- If these don't work, it may indicate hardware-level failure.
When Should You Use Diskpart?
Use Diskpart if:
- CHKDSK fails or doesn't recognize the drive.
- The USB shows as RAW or has no file system.
- You're preparing the USB for reuse after data recovery.
- You want a clean, error-free partition setup.
Steps to Use ATTRIB Command to Remove Hidden or Read-Only Attributes
Sometimes, files on your USB may appear missing because they’re hidden or set as system files. The ATTRIB command helps restore visibility.
How to Use ATTRIB
- In CMD, type:
attrib -h -r -s /s /d X:\*.*
Replace X: with your USB drive letter.
Explanation of Parameters:
- -h: Removes hidden file attribute.
- -r: Removes read-only attribute.
- -s: Removes system file attribute.
- /s: Applies to all subfolders.
- /d: Includes directories.
This command scans all files and folders on the USB and restores their normal attributes, making hidden content visible again.
Additional CMD Fixes
1. Fix MBR Issues (Advanced)
Although rare for USB drives, Master Boot Record (MBR) corruption can affect how the drive is read.
Command:
bootrec /fixmbr
đź’ˇ Note: This is generally for internal drives, but can apply to bootable USBs.
2. Scan for System File Corruption
System-level issues may interfere with USB detection or repair.
Command:
sfc /scannow
This command scans and fixes corrupted Windows system files that may affect hardware recognition.
What to Do If CMD Methods Don't Work?
If none of the CMD methods solve the problem, you still have a few options:
1. Use USB Data Recovery Software
Tools like Donemax Data Recovery, Magoshare Data Recovery, Wondershare Recoverit can help you retrieve lost files even from RAW or formatted drives.
2. Use Third-Party USB Repair Tools
Some free tools offer GUI-based repair methods for USBs:
- Donemax Data Recovery
- Donemax Data Eraser
- HP USB Disk Storage Format Tool
- MiniTool Partition Wizard
- AOMEI Partition Assistant
These may succeed where CMD fails.
3. Consider Physical Damage
If the drive doesn't appear in Disk Management at all, or gets hot quickly, it might be physically damaged. In such cases, replacing the USB or consulting a professional data recovery service may be necessary.
Tips to Prevent USB Drive Corruption
Here are some best practices to reduce the risk of USB corruption in the future:
1. Always Eject Safely
Use the "Safely Remove Hardware" option before unplugging the drive. This ensures that all read/write processes are completed.
2. Avoid Forceful Removal
Unplugging the USB while files are being transferred increases the chances of corruption.
3. Scan for Viruses Regularly
Keep your USB drive and computer safe from malware by using updated antivirus software.
4. Back Up Important Data
Don’t rely solely on USB drives to store essential information. Use cloud storage or external hard drives for redundancy.
5. Use Reliable USB Brands
Cheap or low-quality flash drives are more prone to corruption. Invest in reputable brands like SanDisk, Kingston, or Samsung.
Conclusion
USB flash drives are convenient but fragile devices that can become corrupted due to various reasons like improper removal, file system errors, or malware infections. Thankfully, Windows' Command Prompt offers powerful tools such as CHKDSK, Diskpart, and ATTRIB that allow users to diagnose and repair many common issues.
In this article, we walked through:
- Identifying symptoms of corruption,
- Using CHKDSK to fix errors,
- Cleaning and formatting the drive using Diskpart,
- Revealing hidden files with the ATTRIB command,
- Additional CMD-based troubleshooting tips,
- And preventative measures to protect your USB drive going forward.
While CMD is a robust toolset, it has its limitations. If the damage is beyond repair via CMD, professional recovery software (such as Donemax Data Recovery) or services may be necessary. Regardless, with the knowledge from this guide, you're now well-equipped to handle most USB corruption issues confidently.


Donemax Data Recovery
One of the best data recovery programs to recover deleted, formatted or lost data from PC, Mac, HDD, SSD, USB drive, SD card, camera, RAID, Sever or other storage devices.
Related Articles
- Oct 20, 2023How to Reformat A Time Machine Backup Drive?
- Mar 27, 2024How to Mount and Read EXT4 Partition on Mac?
- Sep 21, 2023How to Partition Hard Drive on Mac?
- Feb 05, 2025Fix/Repair Unallocated External Hard Drive without Losing Data
- Nov 25, 2024Fix External Hard Drive Read-Only on macOS Monterey
- Jul 17, 2023What to Do If An USB Flash Drive Not Working on Mac?

Charles
Charles, who lives in Sydney, Australia, is an editor & writer of Donemax Team. He is good at writing articles related with Apple Mac computers, Windows operating systems, data recovery, data erasure, disk clone and data backup, etc. He loves reading and playing tennis in his spare time and is interested in testing new digital devices such as mobile phones, Macs, HDDs, SSDs, digital cameras, etc.

Gerhard Chou
In order to effectively solve the problems for our customers, every article and troubleshooting solution published on our website has been strictly tested and practiced. Our editors love researching and using computers and testing software, and are willing to help computer users with their problems