Deleting files with reserved names like "nul" or "con" in Windows

Posted: (EET/GMT+2)

 

Today I ran into a file that refused to be deleted or renamed because it was called nul. If you ever hit a similar issue, here's the quick fix.

Windows still reserves a few special filenames that date back to MS-DOS, such as CON, PRN, AUX, and NUL. These names were used to represent system devices. For example, NUL is the null device, similar to /dev/null on Unix systems.

Normally, Windows prevents creating files with these names. However, some tools or automation that bypass normal APIs can still create them. Once the file exists, Explorer and many command line tools may refuse to touch it.

Typical symptoms include:

  • "File not found" errors when trying to delete the file.
  • Rename operations failing with unexpected errors.
  • Explorer being unable to open or remove the file.

The workaround is to use the extended path prefix \\?\, which tells Windows to skip normal path parsing and pass the path directly to the file system.

For example, to delete a file named nul:

del \\?\C:\Path\To\nul

The \\?\ prefix disables the legacy filename checks and allows the operation to reach the file system as-is. This works for other reserved names as well.

You'll typically need an elevated command prompt to remove these files, especially if they were created by system-level tools or build automation.

After deletion, the directory behaves normally again.