Windows file names you cannot use: CON, PRN, AUX, NUL, COM1 and LPT1 (and how to fix them)

Windows says "The specified device name is invalid", a <code>git clone</code> stops with <code>error: invalid path 'aux.js'</code>, or a file called <code>nul</code> appeared and cannot be deleted. These all come from a short list of names that Windows reserves for devices.

The rules

Not allowed on WindowsExamples
Reserved device names, any case, with or without an extensionCON, con.txt, Aux.js, NUL.json, com1.log, LPT9
The characters < > : " / \ | ? * and control charactersReport: final?.pdf
A name ending in a dot or a spacenotes., draft

Names like console.txt, auxiliary.js or con-fig.json are fine: only the exact reserved word before the first dot counts. Microsoft's documentation also lists superscript forms such as COM¹, so avoid those as well.

git clone fails with "invalid path"

A repository made on Linux or macOS can contain aux.js or a:b.txt. Git for Windows refuses to check those paths out. The fix belongs in the repository: on a Linux or macOS machine (or in the code host's web editor) rename the file, update its imports, and commit. Turning off Git's NTFS protection is not a good workaround, because the file still cannot exist normally on Windows.

Deleting or renaming a stray "nul" file

Some tools running under WSL or Git Bash can create a file Windows itself cannot handle. The \\?\ prefix tells Windows to skip its name rules for that one command:

del "\\?\C:\full\path\to\nul"
ren "\\?\C:\full\path\to\aux.js" aux-file.js

Use the full path, starting with the drive letter. From WSL you can also simply run rm nul or mv aux.js aux-file.js in that folder.

Checking many names at once

Paste a list of names into the batch rename tool: rows with reserved names, forbidden characters or a trailing dot or space are marked as blocked, and the rule "remove Windows-illegal characters" cleans the characters for you. For names that look fine but still fail, check for invisible characters with the guide to invisible zero-width characters.

Related

How to batch rename files safely (without uploading them) · Why a batch rename overwrites or skips files (name collisions) · Why file10 sorts before file2, and how to add leading zeros · Renaming a file when only the upper/lower case changes · Remove spaces and special characters from file names · Batch rename tool (names only, in your browser) · Compress many photos at once · Invisible characters in text

Questions

Why can't I name a file CON on Windows?

CON, PRN, AUX, NUL, COM1 to COM9 and LPT1 to LPT9 are reserved device names kept from DOS. Windows treats them as devices rather than files, in any case and even with an extension.

Is con.txt allowed?

No. The reserved word counts with an extension too, so con.txt, aux.js and nul.json are all refused. console.txt is fine.

How do I delete a file called nul?

Use the \\?\ prefix with the full path, for example del "\\?\C:\folder\nul", or delete it from WSL with rm.

Why does git clone say invalid path on Windows?

The repository contains a name Windows cannot store, such as aux.js or a name with a colon. Rename it in the repository from Linux, macOS or the web editor and commit.

Which characters are not allowed in Windows file names?

< > : " / \ | ? * and control characters. Names also cannot end with a dot or a space.

Published .

Try it

Related guides

Newest guides