0XC0000161

STATUS_ILLEGAL_CHARACTER (0XC0000161) Fix

Quick fix: rename any filename with trailing spaces or dots. That's the culprit 90% of the time. Rest of the article covers deeper causes.

Quick Answer

Rename any file or folder that ends with a space or a dot. That's it. If that doesn't work, move on to the registry fix below.

Why This Happens

This error pops up when Windows tries to read or copy a file that violates NTFS filename rules. The most common trigger? Someone created a file with a trailing space or dot — like "notes.txt " or "report.". Windows Explorer won't let you create those normally, but apps (or bad scripts) can. You'll see this error when copying from an external drive, opening a ZIP file, or running a backup job. I've seen it most often on USB drives that were ejected improperly.

Less common causes: corrupt registry values for file associations (usually after a virus removal), or a damaged MFT entry on an NTFS volume. But start with the file rename — it's the fix that works 9 times out of 10.

Fix Steps

  1. Find the exact file. Open a Command Prompt as admin. Run chkdsk X: /f (replace X with the drive letter). This scans for NTFS errors and logs them. Then run dir /x /a to list files with short names. Look for filenames ending with a space — they'll show as "filename.txt " in the output.
  2. Rename the file. Use the ren command. Example: ren "\?\X:\path\to\file.txt " newname.txt. The \?\ prefix bypasses Windows Explorer's name validation. If ren fails, use PowerShell: Get-ChildItem -Path X:\ -Recurse | Where-Object { $_.Name -match '\s+$' -or $_.Name -match '\.$' } | Rename-Item -NewName { $_.Name.TrimEnd('. ') }. This recursively finds and strips trailing spaces and dots.
  3. Check registry for file associations. If renaming doesn't help, the error might be from a bad registry entry. Press Win+R, type regedit, go to HKEY_CLASSES_ROOT\\.txt (or whichever file extension triggers the error). Delete any key with a trailing space in its name. Back up the key first — right-click, Export.
  4. Run SFC and DISM. Corrupt system files can cause this too. Open CMD as admin, run sfc /scannow, then DISM /Online /Cleanup-Image /RestoreHealth. Reboot after.

Alternative Fixes

  1. Use a third-party tool. If you can't rename the file through command line, grab Long Path Tool or Bulk Rename Utility. Free versions handle this.
  2. Copy to a new location. Sometimes the error is isolated to a single folder. Try moving the parent folder to another drive. Use robocopy X:\source Y:\dest /E /COPYALL — robocopy handles illegal characters better than Explorer.
  3. Rebuild the MFT. Last resort. Boot from a Windows repair USB, open Command Prompt, run chkdsk C: /f /r. This rewrites the Master File Table. Takes hours on large drives. Only do this if you've backed up everything.

Prevention Tips

  • Never name files or folders with trailing spaces or dots. It's not valid NTFS, even if some apps let you do it.
  • Disable automatic renaming in file syncing tools (Dropbox, OneDrive). They sometimes botch filenames and add spaces.
  • Run a monthly chkdsk /f on external drives. Catches MFT issues early.
  • Use PowerShell to validate filenames before bulk imports. A simple Get-ChildItem -Recurse | Where-Object { $_.Name -match '[\x00-\x1f\x7f\"\*\:\<\>\?\/\|]' } spots illegal characters.
Pro tip: If you're dealing with a network share, this error can mean the remote server's file system doesn't allow the same characters as NTFS. Check the server's OS — some older NAS devices (like Synology DSM 5.x) reject trailing dots. Strip them before copying.
Related Errors in Windows Errors
0X80097005 MSSIPOTF_E_BAD_OFFSET_TABLE (0X80097005) Fix: Corrupt Font or Signature 0X000004DC ERROR_NOT_AUTHENTICATED (0X000004DC): Your SMB share is lying to you 0X80320028 Fix FWP_E_OUT_OF_BOUNDS (0x80320028) Windows Firewall Error 0XC00D1394 Fix Windows Media Player Error 0XC00D1394 Fast

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.