The Reserved Characters Explained
The Windows NT kernel reserves certain symbols for internal operations, such as path delimiting, command-line parsing, and wildcard expansion. Attempting to create a file with any of these characters will result in an Error 123: The filename, directory name, or volume label syntax is incorrect. Below is the definitive list of characters that cannot appear in a standard file name:
- < (Less than)
- > (Greater than)
- : (Colon)
- " (Double quote)
- / (Forward slash)
- \ (Backslash)
- | (Vertical bar or pipe)
- ? (Question mark)
- * (Asterisk)
While some of these characters have obvious functions like the backslash for paths or the colon for drive letters, others like the pipe or angle brackets are used in command-line interfaces for redirection and piping data between processes. The system blocks them universally to prevent ambiguity.
Handling Quotes and Semicolons
The original query specifically mentioned semicolons and single quotes. It is important to clarify a common misconception: single quotes (') are actually allowed in Windows file names. They are not reserved characters in the NTFS file system. However, double quotes (") are strictly forbidden because they are used to enclose file paths containing spaces in command-line arguments.
Semicolons (;) are also generally permitted in file names on modern Windows systems. They were historically restricted in older DOS-based environments but are valid in NTFS. If you encounter issues with semicolons, it is likely due to a specific application interpreting them as argument separators rather than a core OS limitation. For maximum compatibility, especially when sharing files with other operating systems or legacy software, it is often safer to avoid them, but technically they do not violate NTFS rules.
Workarounds for Special Character Needs
If your workflow requires identifiers that look like reserved characters, you must use alternative Unicode characters or visual substitutes. This approach ensures your files can be created and accessed without triggering system errors.
- Use Unicode Homoglyphs: You can use visually similar characters from other alphabets. For example, use the full-width colon (:, U+FF1A) instead of the standard ASCII colon. Similarly, use the less-than sign from another script if needed. These characters are treated as regular letters by the OS.
- Replace with Dashes or Underscores: The most robust solution is to replace prohibited characters with hyphens (-) or underscores (_). For instance, use
file-name.txtinstead offile:name.txt. - Escape in Scripts: When working with batch scripts or PowerShell, you can escape certain characters using carets (^) or quotes, but this only applies to the command line execution, not the actual file name on disk. You cannot save a file named
test<1>.txteven if you escape it in a command prompt.
Long Path Limitations
Beyond character restrictions, Windows NT has historically enforced a Maximum Path Length Limitation, known as MAX_PATH, which is defined as 260 characters. This limit includes the drive letter, colon, backslashes, and the file name itself. While Windows 10 and later versions allow enabling long paths via the registry or Group Policy, older applications may still fail if the path exceeds this threshold. When dealing with deeply nested folders, keep the total length under 260 characters to ensure broad compatibility.
For more information on managing display settings during startup, which can sometimes affect how file paths are rendered in recovery environments, see Unchecking 'Timed Display List of Operating Systems' in Windows Start-up and Recovery. Additionally, if you need to locate files with complex naming conventions over a network, refer to Windows Search: Finding Exact Names with Special Characters in Shared Lan Folders.
Renaming Files Programmatically
If you have existing files with problematic names (created via Linux subsystems or third-party tools), renaming them through the GUI might be difficult if the explorer interface glitches. Use PowerShell to rename files safely. The Rename-Item cmdlet handles special characters better than the standard dialog box in some edge cases.
Rename-Item -Path "C:\Old\Name.txt" -NewName "C:\New_Name.txt"
Always verify the new name does not contain any of the reserved characters listed above. If you are dealing with archives that contain extended Latin characters, be aware that standard ZIP tools might struggle with encoding. Consider using Error Creating Tar Archive with Extended Latin Characters in Windows 10 techniques if you are moving files between different encoding standards.
Common Pitfalls in Batch Processing
When writing batch files, never assume user input for file names will be clean. Always sanitize inputs. If a user tries to pass a file name with a pipe character into a script, the script might interpret it as a command pipeline, leading to unexpected behavior or security vulnerabilities. Use %~1 to properly handle quoted arguments in batch files, which strips the surrounding quotes and prevents injection attacks.
Frequently Asked Questions
Can I create a file named CON or PRN?
No, Windows reserves device names like CON, PRN, AUX, NUL, COM1-COM9, and LPT1-LPT9. Attempting to create a file with these names will fail regardless of whether they contain special characters. You must append an extension or modify the name slightly.
Why does my script fail when I try to read a file with spaces?
Command-line interpreters treat spaces as delimiters between arguments. To fix this, wrap the file path in double quotes. For example, use type "C:\My Folder\file.txt" instead of type C:\My Folder\file.txt.
Is it safe to use emojis in file names?
Yes, modern Windows versions support Unicode emoji characters in file names. However, some older backup software or network shares may not handle them correctly, potentially causing synchronization errors or displaying garbled text.
How do I find files that have illegal names already?
You can use PowerShell with the Get-ChildItem cmdlet and filter using regular expressions to identify files containing reserved characters. This allows you to batch rename them programmatically before they cause further issues with applications.
What happens if I force a file name with a colon using Linux subsystems?
If you create such a file via WSL (Windows Subsystem for Linux), Windows Explorer may display it incorrectly or refuse to open it. It is highly recommended to rename the file within WSL to a valid NTFS-compliant name before accessing it from Windows native applications.