Windows 11 Error 123: The Filename, Directory Name, or Volume Label Syntax Is Incorrect
Why This Error Happens
Error 123 occurs when Windows encounters invalid characters, reserved names, or malformed syntax in a file path, command, or script. This is commonly triggered by illegal characters (such as *, ?, <, >, |, :, or "), paths exceeding the 260-character limit (MAX_PATH), or improperly formatted commands in batch scripts, Command Prompt, or PowerShell. It can also arise from copy-paste errors where hidden Unicode characters or extra spaces get embedded into a path.
Step-by-Step Resolution Guide
-
Check the file/folder path for invalid characters
Open File Explorer, navigate to the affected file or folder, and inspect the name for characters like\ / : * ? " < > |. Rename the file/folder removing any special characters — right-click → Rename. -
Verify the path length
Long paths exceeding 260 characters can trigger this error. Move the file closer to the root drive (e.g.,C:\Data\file.txtinstead of a deeply nested folder), or enable long path support:
- Open Registry Editor (
regedit) - Navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem - Set
LongPathsEnabledto1 - Restart your PC
- Inspect Command Prompt/PowerShell syntax
If the error occurs while running a command (e.g.,xcopy,robocopy,del), ensure paths with spaces are wrapped in quotes:
xcopy "C:\My Folder\file.txt" "D:\Backup\"
Also check for trailing backslashes before closing quotes, as these can break syntax parsing.
-
Check batch/script files for hidden characters
If the error originates from a.bator.ps1script, open it in Notepad++ or VS Code and enable “Show all characters” to detect hidden Unicode or non-printable characters that may have been introduced via copy-paste. -
Recreate the file/folder from scratch
If renaming doesn’t resolve it, create a new file/folder with a simple ASCII name (letters, numbers, underscores only) and move the original content into it.
Alternative or Verification Steps
- Verify the fix: Re-run the original command or re-attempt the file operation (copy/move/delete) that triggered Error 123 — it should now complete without the syntax error.
- Alternative: If the issue persists in a specific application, try performing the same file operation via Command Prompt with
dir /xto reveal the short (8.3) filename, and use that as a workaround for problematic long or special-character names.