You get “The directory name is invalid” error when opening a file on your PC, USB drive, or SD card because of several reasons like bad sectors on the drive, faulty device drivers, or damaged SATA port.
You might’ve just entered the wrong directory in some cases. For example, when using the Run program in Windows, you could’ve typed the directory name incorrectly, which means the directory name isn’t valid and won’t open.
We explain how you can resolve this error and how to recover your files in cases where necessary.
How to Fix “The Directory Name is Invalid” in a Few Easy Steps
Now that you’ve understood what the directory name is invalid error means, let’s discuss a few methods that can help you fix the error and regain access to your folder on Windows, USB drives, or SD cards.
Step 1. Check the Path and File and Folder Name
Sometimes the error is mechanical rather than technical. When you write the path or file or folder name incorrectly, you’ll receive the directory name is invalid on Windows 10 or 11.
For example, say you have a folder containing files created using Microsoft Word and Excel, and both have the same name. When you try to access the path “C:\Office\Documents\filename”, you’ll receive an error since you haven’t mentioned the file extension. Windows won’t know which file to open since multiple files with the same name exist in that folder.
The file extension is important to access the file. Note that Microsoft Word can also export files in other extensions like PDF. Don’t assume a file is a .doc file if it was created using Microsoft Word.
You should also check you’re using the correct naming convention. For example, you might be using a forward slash (C:/) instead of a backward slash (C:). This is incorrect and will result in the directory name is invalid error. The File Explorer and the Run program can automatically fix the forward slash, but it’s a problem when you’re using tools like Command Prompt.
Step 2. Try Different USB Ports
The USB port you’re using for your USB drive, external hard drive, or SD card reader may be damaged or faulty. Just try using a different USB port to see if the error persists. If you’re able to solve the error, seek help from a professional to get your port fixed.
Step 3. Make Data Backup If Possible
If you’re still seeing the directory name is invalid when using/inserting a USB, pendrive, or SD card, it’s best to create a backup. This ensures your data is safe.
If you end up damaging the storage device somehow, you’ll need to put extra time and effort into recovering data from a broken flash drive or failed SD card. In the worst cases, you’ll need to contact a professional data recovery service.
However, if you have a backup, you can use it to recover the data yourself. You can use a recovery tool like Disk Drill (read our Disk Drill review) to do this.
How to Create Byte-to-Byte Backup
Disk Drill, one of the best data recovery apps on the market, allows you to create a backup image of your storage device using its Byte-to-Byte backup feature. Here’s the complete process for creating a backup using Disk Drill:
- Download Disk Drill and install it on your PC.
- Launch Disk Drill and switch to the Drive Backup section from the left sidebar.
- Select a disk you want to backup and click on Byte-to-Byte Backup at the top-right corner.
- Enter a path where you want to store the backup and click OK to create the backup.
You can use this image to recover files if needed by attaching the image as a disk in Disk Drill as we explain in step 6.
Step 4. Run CHKDSK in Command Prompt
CHKDSK is a built-in command-line utility in Windows that helps detect and fix disk-related issues like bad sectors and filesystem errors. If these issues are the reason why you’re getting the device name is invalid on Windows 10/11, CHKDSK can help.
The CHKDSK command is generally used with the /r switch. For example, the command might look like this:
chkdsk C: /r
The command checks volume C for bad sectors and attempts to repair them so they’re readable within the file system.
Note: The /r switch includes the /f switch’s function so you don’t need to type the /f switch.
However, instead of using /r, you should use the following command:
chkdsk C: /f /r /x
You need to run the command in CMD. Press Ctrl + R, type cmd, and press Ctrl + Shift + Enter to launch an elevated Command Prompt. Then, copy and paste the command above (but replace the drive letter).
Executing this command scans the file system and sectors and fixes those errors, all with the same command. More importantly, the command also dismounts the drive first if necessary.
Step 5. Format Your SD Card or USB Drive
If CHKDSK didn’t help, you should consider formatting as your last resort option. However, this option is viable if you’re receiving the directory name is invalid when inserting an SD card or USB pen drive.
If you’re unable to format the SD card or pen drive because of errors, use another device or a different operating system to format the device. While there are a few ways to format an SD card without losing data or format a USB stick without losing data, you can always format and use the backup you created using Disk Drill to recover data.
Step 6. Retrieve Your Data With Recovery Tool
After you’ve formatted your USB flash drive or SD card, you’ll need to recover the data from the formatted SD card or formatted USB drive. You can use Disk Drill to recover data from formatted drives, provided you had performed a quick format. However, the chances of recovery are still the best when you create a byte-to-byte backup (as explained in step 3).
Note: The free version allows recovering up to 500MB of data.
- Start by attaching the disk image using the Attach disk image option on the app’s home screen. Click on the option and select the image file to attach.
- You’ll now see the image file in the list of disks. Select the disk image from the list and click on the Search for lost data button.
- Once the scan is complete, select the files you want to recover. The backup contains data from the entire disk. However, you might have been trying to access a specific file when you get the directory name is invalid error. The good thing is, Disk Drill helps you filter the list of recoverable files. You can choose to recover all files or filter the list for specific file types you want to recover. For example, you can select Pictures from the left sidebar to only see pictures in the list. Alternatively, you can narrow down the list further based on a file extension. For example, you can type “.png” in the search bar at the top-right to only see png files in the list. You can also preview the images by clicking on the tiny eye icon to determine if that’s the file you want to recover.
- Select the files you want to recover by selecting the box to the left of the filename. Then click the Recover button at the bottom.
- Select a recovery path. This is where Disk Drill will save the recovered files.
That’s all you need to do to recover data from an SD card or USB pen drive and regain access to your directories.