Fix "Directory Name Is Invalid" When Opening Files
In this article
When you see the error "The directory name is invalid" while trying to open a file, it usually means Windows cannot access the folder path where the file is stored. This often happens after moving, renaming, or deleting a folder, or when a shortcut points to a location that no longer exists. The fix is to correct the file path, clear the invalid reference, or reset the app that is trying to open the file. Below are step-by-step solutions that work for most Windows versions (10 and 11).
What You'll Need
- Administrator access to your Windows PC (for some steps).
- The exact file name and the folder where it should be located.
- If the file is on a network drive or external drive, make sure that drive is connected and accessible.
Step-by-Step
- Check the file location. Right-click the file (or its shortcut) and select Properties. Look at the Location or Target field. If the folder path shown does not exist (for example, it references a drive letter that is no longer assigned, or a folder you deleted), that is the cause. If the path is correct, proceed to the next step.
- Restore or recreate the missing folder. If the folder was accidentally moved or renamed, move it back to the original path or create a new folder at that exact location. For example, if the path is
C:\Users\YourName\Documents\Projectsand that folder is missing, create it using File Explorer. Then move the file into that folder. - Update or remove broken shortcuts. If you are opening the file from a shortcut, right-click the shortcut, choose Properties, and in the Shortcut tab, click Find Target to locate the actual file. If the target cannot be found, delete the shortcut and create a new one by right-clicking the actual file and selecting Send to > Desktop (create shortcut).
- Clear the app's recent files list. Some applications (like Word, Excel, or Notepad) store a list of recently opened files. If a file was moved, the app may try to open an old path. In most apps, go to File > Open and navigate to the correct location manually. To clear the recent list, open the app's settings or options and look for "Clear recent files" or "Reset recent documents." The exact wording varies by app.
- Run a disk check. If the file is on a drive that has file system errors, run
chkdsk. Open Command Prompt as administrator (press Windows key, type "cmd", right-click and select Run as administrator), then typechkdsk C: /f(replaceC:with the drive letter of the drive containing the file). You may need to restart your PC to let the scan run. This can fix corrupted folder entries. - Reinstall the application. If the error appears only when opening files from a specific program, the app's installation may be corrupted. Uninstall the program from Settings > Apps (or Control Panel), then reinstall it from the official source. This resets the app's file associations and internal path references.
- Reset the file association. If the error happens when double-clicking the file, the file type may be associated with a program that no longer exists. Right-click the file, select Open with, choose the correct program, and check "Always use this app to open .[extension] files." If the program is not listed, click Choose another app and browse to the program's executable.
Common Mistakes
- Ignoring the exact path: The error often appears because the path has a typo or an extra space. Copy the path from the error message and paste it into File Explorer to see if it works.
- Deleting the file instead of fixing the path: Do not delete the file just because you cannot open it. First, try moving it to a different folder (like your Desktop) and opening it from there.
- Assuming it's a permission issue: The error is not about permissions; it's about the folder path being invalid. Do not spend time changing file permissions unless you have confirmed the path is correct.
Tips
- Always use the Copy path option in File Explorer (right-click a file or folder, then select Copy as path) to get the exact path without typos.
- If you frequently move files, consider using a cloud sync service (like OneDrive) that keeps paths stable across devices.
- When creating a new folder, avoid using special characters like
?,*, or:in the folder name—these can cause path errors. - If the file is on a network drive, map the drive to a letter (e.g.,
Z:) so the path remains consistent.
Troubleshooting
If the steps above do not resolve the error:
- Restart your computer. Sometimes a temporary glitch in the file system can cause this error, and a reboot clears it.
- Check if the drive is connected. If the file is on an external drive or SD card, make sure it is properly connected and recognized. Try a different USB port.
- Use a different file explorer. Try opening the file from a command prompt: type
start "" "C:\path\to\file.ext"(replace with your actual path). If it opens, the issue is with the File Explorer shell. - Run System File Checker. Open Command Prompt as administrator and type
sfc /scannow. This checks for corrupted Windows system files that might affect file access. - If the file is on a network share, verify that you have the correct network credentials and that the share is still available. Try accessing the share directly via its UNC path (e.g.,
\\server\share\folder\file). - As a last resort, use a file recovery tool to copy the file to a new location. However, be careful—this is not a substitute for fixing the underlying path issue.
Frequently Asked Questions
What does "directory name is invalid" mean?
It means Windows cannot find the folder path that the file is supposed to be in. The path may be broken because the folder was moved, renamed, or deleted, or because the drive letter changed.
Can I open the file if I don't know where it is?
Yes, you can search for the file by its name using the search box in File Explorer. Once found, you can open it directly from its new location.
Why does this happen with shortcuts?
Shortcuts store the original path. If the target file moves, the shortcut becomes invalid. Updating the shortcut's target path fixes it.
Does this error occur on Mac or Linux?
No, this specific error message is from Windows. Other operating systems have their own path-related errors, but the cause is often similar—a broken or missing folder path.
Will reinstalling the app delete my files?
No, reinstalling the app only removes the program, not your personal files. However, you should back up any important documents before reinstalling, just in case.
Can I prevent this error in the future?
Yes, avoid moving or renaming folders that contain frequently used files. If you must move them, update any shortcuts or recent file lists afterward. Also, keep your drive healthy by running disk checks periodically.