Inserting a USB thumb drive, opening an external hard drive, clicking a desktop shortcut, or running a script in Windows 11 only to be blocked by the prompt “The directory name is invalid” indicates that the operating system file system cannot resolve the targeted directory path. This error typically occurs when USB drive letters clash, file paths contain corrupted directory pointers, card readers experience driver desynchronisation, or Command Prompt starts in an unrecognised working directory.
Change the Drive Letter in Disk Management
When external storage devices (such as USB drives, SD cards, or external SSDs) are assigned a drive letter that conflicts with a hidden network share or optical drive, Windows fails to open the root directory.
- Press Windows Key + X and select Disk Management.
- Locate your external USB drive or SD card in the lower graphical volume list.
- Right-click the volume partition and select Change Drive Letter and Paths.
- Click the Change button.
- Select the radio button Assign the following drive letter.
- Choose a drive letter further down the alphabet that is unlikely to be contested (such as M:, P:, or X:).
- Click OK and confirm the warning dialogue.
- Open File Explorer and verify that the drive opens cleanly under its new letter.
Update and Reinstall USB Controller Drivers
Corrupted USB root hub controllers can misreport storage partition boundaries to the Windows kernel, triggering path errors during read requests.
- Press Windows Key + X and select Device Manager.
- Expand the Universal Serial Bus controllers category.
- Right-click your external storage controller or USB Mass Storage Device and select Uninstall device.
- Unplug your USB device from the computer.
- Restart your computer.
- Once Windows boots back up, plug the USB drive into a different physical USB port (preferably directly on the motherboard rather than via an unpowered hub). Windows will reinstall pristine controller drivers.
Repair Corrupt File System Sectors via CHKDSK
Improperly ejecting external storage without using “Safely Remove Hardware” frequently corrupts partition Master File Tables (MFT) or directory allocation structures.
- Press Windows Key + S, type cmd, right-click Command Prompt, and select Run as administrator.
- Execute the file system check command, replacing
X:with your actual external drive letter:chkdsk X: /f /r - Press Enter. CHKDSK will examine file allocation tables, validate directory index entries, and repair corrupted pointers.
- Once the scan reaches 100% completion, access the directory in File Explorer.
Fix Command Prompt “Directory Name Is Invalid” on Startup
If opening Command Prompt or PowerShell triggers the error instantly, the shortcut working directory or AutoRun registry key has become invalid.
- Right-click your Command Prompt shortcut and select Properties.
- Under the Shortcut tab, examine the Start in field.
- Ensure the field contains a valid path, such as
%HOMEDRIVE%%HOMEPATH%orC:\Windows\System32. - Next, press Windows Key + R, type regedit, and press Enter.
- Navigate to:
HKEY_CURRENT_USER\Software\Microsoft\Command Processor - Check if an AutoRun string value exists in the right pane. If present and pointing to a nonexistent folder, right-click and delete it.