Skip to main content

Filename Sanitizer — Remove Illegal Characters, Get a Safe Filename

Strip illegal characters and make any string a safe cross-platform filename, in your browser

  • Runs locally
  • Category Developer & DevOps
  • Best for Checking file type, size, metadata, and obvious mismatch signals before sharing.
Safe filename(s)

What this tool does

A filename sanitizer that turns any messy string into a safe, valid filename that works on Windows, macOS and Linux. It removes the nine characters Windows forbids in a name (backslash, forward slash, colon, asterisk, question mark, double quote, less-than, greater-than and the pipe bar) along with invisible control characters, then replaces runs of whitespace with an underscore or a hyphen so the result has no awkward gaps. It also fixes the traps that bite people later: a name ending in a dot or a space (Windows silently drops them), and reserved device names like CON, PRN, NUL, COM1 and LPT1 that refuse to save no matter what folder you are in. You can lowercase the whole thing, keep the file extension while everything before it is cleaned, and truncate to a length limit (255 by default) without cutting the extension off. Paste one name or a whole list, one per line, and copy the cleaned batch with a click. Everything runs locally; nothing is uploaded.

Tool details

Input
Text + Numbers
The page exposes text boxes, numeric controls, file pickers, or structured inputs depending on the tool.
Output
Live result + Copy
The result area focuses on usable output, with copy, download, or preview actions when supported.
Privacy
Browser-side processing
The main tool logic does not call an external API, so inputs normally stay in the current tab.
Save / share
Shareable URL state
Key settings are encoded in the URL so another person can reopen the same setup.
Performance budget
Initial JS <= 9 KB
No WASM budget is declared, keeping the tool quick to open on mobile.
Best fit
Developer & DevOps · Developer
Category and role tags drive related tools, internal links, and quick fit checks.

How to use

  1. 1. Input

    Paste or drop your content into the tool panel.

  2. 2. Process

    Click the button. All processing is local in your browser.

  3. 3. Copy / Download

    Copy the result or download to disk in one click.

How Filename Sanitizer fits into your work

Use it before upload, handoff, archive, support review, or any moment where a file needs one local check before it leaves your machine.

File jobs

  • Checking file type, size, metadata, and obvious mismatch signals before sharing.
  • Preparing mixed folders for upload, archive, intake, or review.
  • Keeping sensitive files in the browser instead of sending them to an account-based service.

File checks

  • Do not treat the extension alone as proof of the real file type.
  • Review metadata before a file goes to customers, vendors, or a public page.
  • Keep the original file until the copied, converted, or exported result is verified.

Good next steps

These links move the current task into a more complete workflow.

  1. 1 URL Slug Generator Turn any title into a clean URL slug — lowercase, dashes, ASCII-safe transliteration, multiline batch — browser-only Open
  2. 2 Text File Cleaner Upload a text file and remove BOM, null bytes, trailing spaces, and excessive final blank lines locally. Open
  3. 3 Find and Replace Text Batch find-and-replace on big text — regex, $1 capture groups, whole-word, case toggle, multiple chained rules — runs entirely in your browser Open

Real-world use cases

  • Save a downloaded report whose title has a colon

    A web app offers to export 「Q3 Review: Sales Ops Final.pdf」 and Windows refuses the download because of the colon. Paste the proposed name, get 「Q3_Review_Sales_Ops_Final.pdf」 back in one step, and the file saves on the first try instead of failing with a cryptic 「invalid file name」 dialog.

  • Clean a batch of names before a bulk rename

    You scraped a hundred article titles to use as filenames and half of them contain slashes, quotes or trailing dots. Drop the whole list in, one per line, and the tool returns a parallel list of safe names you can paste straight into a rename script or a spreadsheet column, with no name that will choke the rename halfway through.

  • Generate attachment names that survive email and zip

    Reserved names like 「CON」 and 「NUL」, or a stray trailing space, can make a file silently disappear when a recipient on Windows unzips your archive. Run each intended attachment name through the sanitizer first so 「CON.log」 becomes 「CON_file.log」 and no file vanishes on the other end of the transfer.

  • Build safe filenames inside an export feature

    You are coding a 「download as file」 button and need to turn a user-supplied title into a filename without writing the strip-rules by hand. Use the tool to confirm exactly what your output should look like for tricky inputs — emoji, CJK text, reserved names, 300-char titles — then mirror the same rules in your code with confidence.

Common pitfalls

  • Only removing the forward slash and forgetting the other eight Windows-illegal characters. A name with a colon or a pipe still fails to save on Windows even though it looked fine on the Mac where you made it. Strip all nine, not just the slash.

  • Ignoring reserved device names. 「NUL.txt」 looks like an ordinary file but will not save on any Windows machine. A regular character filter never catches it because every character is legal; you have to check the whole base name against the reserved list.

  • Truncating a long name by chopping the end and losing the extension. 「very-long-title.pdf」 cut to 255 characters can drop the 「.pdf」, and the file then opens in the wrong program. Always trim the base name and keep the extension intact.

Privacy

Every step — stripping illegal characters, the reserved-name check, the trailing-dot fix and the length truncation — is plain JavaScript running in your browser tab. The names you paste never leave the page and are not logged anywhere. Filenames sometimes carry sensitive context, like a client name or a project codename, so it matters that this tool keeps them local. There is no shareable URL for the input here precisely because a filename can be private; copy the cleaned result and use it directly.

FAQ

Tool combos

Folks in your role tend to reach for these alongside this tool.

Made by Toolora · 100% client-side · Updated 2026-06-13