Recover Files from SD Card Using CMD
In this article
Yes, you can recover files from an SD card using Command Prompt (CMD) on Windows, but only in specific scenarios—mainly when the card is not physically damaged and the files were lost due to accidental deletion, corruption, or a quick format. CMD uses built-in tools like chkdsk and attrib to fix file system errors and unhide files, but it cannot perform deep recovery of overwritten data. For truly deleted files (not just hidden or corrupted), you'll need third-party recovery software, as CMD has no undelete command.
What CMD Can and Cannot Do
Command Prompt is a powerful text-based interface that can interact with storage devices at a low level. For SD cards, it can:
- Check and repair file system errors using
chkdsk. - Unhide files and folders that have been hidden by malware or system errors using
attrib. - Access the card's volume and run basic file operations.
However, CMD cannot recover files that have been permanently deleted (i.e., their directory entries are gone and the space is marked as writable). It also cannot handle physical damage, severe corruption, or data that has been overwritten. For those cases, you need dedicated recovery software that reads raw data blocks.
When to Use CMD for SD Card Recovery
CMD is most effective in these situations:
- Files are hidden but still present – If your photos or documents suddenly disappeared but the card still shows used space, they may be hidden.
attribcan make them visible again. - File system errors after improper ejection – If Windows prompts you to format the card or says it is not accessible,
chkdskcan often repair the file system and restore access. - Quick format (not full format) – A quick format only clears the file table, leaving the actual data on the card. While CMD cannot directly recover it, it can sometimes help if the issue is a corrupted file system.
For accidental deletion, recovery software is the standard approach because it scans the raw storage for file signatures.
How to Use CMD to Recover Files: Step-by-Step
Follow these steps carefully. Always work on a copy of the SD card if possible, not the original, to avoid overwriting data.
- Connect the SD card to your PC via a card reader. Note the drive letter assigned (e.g.,
E:). - Open Command Prompt as Administrator – Press
Windows + X, select “Command Prompt (Admin)” or “Windows PowerShell (Admin)”. - Run chkdsk to repair the file system – Type
chkdsk E: /f(replaceE:with your card’s letter). This will attempt to fix errors and make the card accessible again. Do not use/ryet, as it takes much longer and may further stress a failing card. - If the card is accessible, unhide files – Type
attrib -h -r -s /s /d E:\*.*(again, replaceE:). This removes Hidden, Read-only, and System attributes from all files and folders, making them visible in File Explorer. - Check if files are now visible – Open the card in File Explorer. If you see your files, copy them to your computer immediately.
- If files are still missing, try a different approach – CMD cannot recover deleted files. At this point, you should use a dedicated recovery tool (see below).
Note: If chkdsk reports severe corruption, stop using the card and use recovery software that creates a disk image first.
Common Problems and Misconceptions
One common misconception is that chkdsk can recover deleted files. It cannot; it only repairs the file system structure. Another is that CMD has an “undelete” command – it does not. The recover command exists but only works on a file-by-file basis and requires the file’s exact name and location, which you usually don’t know after deletion. Also, running chkdsk on a physically failing card can worsen the damage, so always stop if you hear clicking or see I/O errors.
CMD vs. Third-Party Recovery Software
CMD is free and built-in, but it’s limited. Third-party tools like PhotoRec, Recuva, or TestDisk offer deep scanning that reads raw data and can reconstruct files based on signatures (JPEG, PNG, etc.). They are more effective for deleted files. However, they are not built into Windows, and some are paid. For a cost-free option, PhotoRec is open-source and runs from command line (but it’s not CMD; it’s a separate program).
Safety Tips Before You Start
- Stop using the SD card immediately after data loss to prevent overwriting.
- Work on a copy – Use a tool like Win32 Disk Imager to create an image of the card, then run recovery on the image.
- Do not format the card unless you have already recovered what you need.
- If the card is physically damaged (cracked, bent, or water-damaged), CMD will not help; consider professional recovery services.
Alternatives to CMD
If CMD fails, you have other options:
- Data recovery software – Install on your PC, scan the card, and recover files. Many offer free trials.
- Linux live USB – Booting from a Linux USB can sometimes access cards that Windows cannot, using tools like
testdisk. - Professional recovery services – For critical data, labs can disassemble the card and read memory chips directly, but this is expensive.
Frequently Asked Questions
Can I recover deleted photos from SD card using CMD?
No, CMD cannot recover deleted photos. Deletion removes the file’s directory entry, and CMD has no undelete function. You need third-party recovery software that scans the raw storage for file signatures.
What is the attrib command for SD card recovery?
The attrib command changes file attributes. Running attrib -h -r -s /s /d E:\*.* removes Hidden, Read-only, and System attributes from all files and folders on the E: drive. This is useful when files have been hidden by malware or a file system error, but it does not recover deleted files.
Does chkdsk recover files from a corrupted SD card?
chkdsk repairs the file system structure (like the master file table). It can make the card accessible again, but it does not recover deleted files. It may also cause data loss if it moves corrupted files to a found.000 folder, which you can manually check.
Is it safe to run chkdsk on an SD card?
It is safe if the card is not physically damaged. However, if the card is failing, running chkdsk can stress it further and cause more damage. Always back up data first if possible, and consider using a disk image.
What should I do if CMD says “Access is denied”?
This usually means you are not running Command Prompt as administrator, or the SD card is write-protected. Close CMD, right-click it, and select “Run as administrator”. If the card has a physical lock switch, ensure it is unlocked.
Can I recover files from a formatted SD card using CMD?
After a quick format, the file system is rebuilt, but the data remains. CMD cannot recover it because there is no file table to reference. Use recovery software that scans for file signatures instead.