You're working on a Windows 10 or 11 machine—maybe copying files, running a batch script, or installing software—and suddenly you get this error: ERROR_ILLEGAL_CHARACTER (0x00000246). The exact message reads: "An illegal character was encountered." It usually shows up when a program tries to process a filename, folder path, or data stream that contains a character Windows won't accept. Common triggers: saving a file with a colon in the name, pasting a path with a trailing backslash, or running a script that reads a corrupted text file with a null byte.
What causes error 0x00000246?
Windows has a strict set of characters it won't allow in file or folder names. These include: \ / : * ? " < > |. If you try to create a file called report:final.txt or a folder named notes?data, the operating system throws this error. The real root cause is almost always a program or user sending a string containing one of these characters to the file system.
But it's not just filenames. Sometimes it's in the data being written—like a registry import file that has a bad character in a value, or a batch script that uses a pipe | inside a for loop without escaping it. I've seen this happen with backup tools that try to restore a file with a trailing space in the name. Windows trims trailing spaces, but the tool doesn't, and boom—there's your error.
How to fix it: Step by step
Before you start, identify where the error appears. Is it during file copy, script execution, or a system operation? That tells you where to look.
- Check the file or folder name you're trying to create or access.
Look for these characters:\ / : * ? " < > |. If you find one, rename the file or folder. Right-click it, choose Rename, and remove the bad character. Replace colons with hyphens, asterisks with the word "star". Then hit Enter. - Test the path in Command Prompt.
Open Command Prompt as admin. Typeecho %cd%to see your current directory. Then trydir "C:\path\to\file"—replace the path with the one you think is bad. If you get "File Not Found", that path doesn't exist. The error 0x00000246 means the path exists but has a bad character. - For script errors, open the script in Notepad++ or a text editor that shows hidden characters. Turn on "Show All Characters" (View > Show Symbol > Show All Characters). Look for non-ASCII characters like a stray bullet point or a null byte (shown as NUL). Delete them. Save the file as UTF-8 without BOM.
- If it's a registry import, open the .reg file in Notepad. Look for any line with a pipe
|or angle brackets< >. These aren't allowed in registry value names. Replace them with something safe, like hyphens. Save and re-import. - For backup/restore operations, check the source files. Open File Explorer, navigate to the folder that contains the problem file. Sort by Name. Look for any file with a trailing space or period—Windows hides these sometimes. You can see them in Command Prompt with
dir /x. To rename a file with a trailing space, useren "badfile. " "badfile.txt"—the quotes are crucial. - Reboot and try again. Some file locks clear on restart. If the error came from a temporary file (like in
%TEMP%), reboot first, then delete the offending file manually.
Advanced fix: Using PowerShell to find bad characters
If you don't know which file is causing the problem, use PowerShell to scan a directory. Open PowerShell as admin and run:
Get-ChildItem -Path "C:\YourFolder" -Recurse | ForEach-Object {
if ($_.Name -match '[\\/:*?"<>|]') {
Write-Output ("Bad char in: " + $_.FullName)
}
}
This lists every file or folder with an illegal character. Then rename using the same approach. For a single file:
Rename-Item -Path "C:\bad:file.txt" -NewName "bad-file.txt"
What to do if it still fails
If the error persists after renaming everything, check for a corrupt file system. Open Command Prompt as admin and run chkdsk C: /f (replace C: with your drive letter). This scans for file system errors and repairs them. After that, run sfc /scannow to fix system file corruption. I've seen a corrupted NTFS master file table cause phantom illegal character errors.
Another sneaky cause: antivirus software that blocks file creation with certain names. Temporarily disable your antivirus (real-time protection) and try the operation again. If it works, add an exception for that folder or file type.
Finally, if you're working with a network drive or cloud-synced folder (like OneDrive), the illegal character might be in the cloud file name. Open the web interface for the cloud service, find the file, and rename it there. Then sync back down.
Bottom line: Error 0x00000246 is almost always a filename or data-stream issue. Start by hunting down those forbidden characters—colons, pipes, asterisks—and you'll usually fix it in under five minutes.