Windows filename sanitizer

Windows rejects \ / : * ? " < > |, control characters, trailing dots and spaces, and DOS device names (CON, PRN, AUX, NUL, COM1–9, LPT1–9).

How to use the Windows filename sanitizer

What does the Windows filename sanitizer do?

Clean a filename for Windows: remove <>:\/|?* and control characters, fix trailing dots/spaces, and catch reserved names like CON, PRN, AUX, NUL; It applies this page-specific rule: the cleaner takes only the last path segment (so a pasted Windows path does not become one giant illegal name).

Which inputs does this tool use?

To clean a filename for windows: remove <>:\/|?* and control characters, fix trailing dots/spaces, and catch reserved names like con, prn, aux, nul, enter Proposed name; keep every value in the same example; the page then updates the result from the current values; Start with a familiar case covered by this rule - Reserved device names are still reserved even with an extension: CON.txt is as bad as CON - so the expected result can confirm the settings.

How should the tool result be read?

For a result intended to clean a filename for windows: remove <>:\/|?* and control characters, fix trailing dots/spaces, and catch reserved names like con, prn, aux, nul, reserved device names are still reserved even with an extension: CON.txt is as bad as CON; read proposed name together with the original proposed name rather than as an isolated answer, and confirm that its units or structure match the intended use.

What characters are illegal?

When the goal is to clean a filename for windows: remove <>:\/|?* and control characters, fix trailing dots/spaces, and catch reserved names like con, prn, aux, nul, \ / : * .

Why is CON.txt bad?

When using the page to clean a filename for windows: remove <>:\/|?* and control characters, fix trailing dots/spaces, and catch reserved names like con, prn, aux, nul, windows still treats CON as a device, extension or not.

Limits and accuracy

When using this tool to clean a filename for windows: remove <>:\/|?* and control characters, fix trailing dots/spaces, and catch reserved names like con, prn, aux, nul, this does not create files and does not know about MAX_PATH on a specific machine; check the result in its intended destination before relying on it for important work; keep proposed name until the output has been checked in its intended destination.

How this works

The cleaner takes only the last path segment (so a pasted Windows path does not become one giant illegal name). Illegal characters become underscores. Trailing spaces and dots are stripped because Explorer will not keep them.

Reserved device names are still reserved even with an extension: CON.txt is as bad as CON. If the cleaned name matches one of those, an underscore is prepended.

This does not create files and does not know about MAX_PATH on a specific machine. It is a name check, not a save dialog.

Frequently asked questions

What characters are illegal?

\ / : * ? " < > | and ASCII control characters 0–31.

Why is CON.txt bad?

Windows still treats CON as a device, extension or not.

macOS / Linux?

They allow more characters. This page is the Windows-safe subset that also works on the others.

Trailing dot?

Removed. Windows will not store it.