Path Sanitizer
Path Sanitizer Fixes the Filename First
- sanitized_path
You know the failure: you build a workflow that names its output from the prompt, run it with a great idea, and the save node quietly refuses or mangles the file. The culprit is usually a : from a timestamp, a / that snuck into a filename from a prompt phrase, or a Windows-reserved name like CON. Path Sanitizer is a one-node pack that fixes the string before it ever reaches the save node, so your output names stay readable and your workflow stops dying on punctuation.
It's not a glamorous node. It's plumbing - the kind of thing that earns zero community drama because when it works, you never think about it again. But if you've ever handed a save node a prompt:style/seed string and watched it choke, this is the fix.
What it actually does
The node lives under utils/string and takes one string in, returns one string out. Under the hood it's pure Python stdlib - re and unicodedata, nothing to install - running this pipeline:
- NFKC unicode normalization, so full-width and compatibility characters collapse to their standard form before anything else happens.
- Invalid character replacement. Anything matching
[<>:"/\\|?*\x00-\x1f]gets swapped for yourreplacement_char(default_). Note the slash and backslash are in there, which matters - more on that below. - Windows reserved names. If the base name is
CON,PRN,AUX,NUL, orCOM1–9/LPT1–9, it gets prefixed (soCONbecomes_CON). Those names are illegal on Windows no matter where the file lives, so the node treats them as universal hazards. - Trailing period/space stripping - Windows forbids those at the end of filenames.
- Length truncation that tries to keep the extension intact, so
a_really_long_name...pngstays a.pngafter it's cut down to yourmax_length.
If everything gets stripped and the result is empty, it returns "unnamed" rather than an empty filename. Small touch, saves a crash.
The inputs that matter
Only one is required; the rest have sane defaults and you'll rarely touch most of them.
input_string(required) - the string to clean. Wire this from your prompt-builder, timestamp node, or whatever's feeding the filename.replacement_char(default"_") - what invalid characters become. If you'd rather see hyphens than underscores, set it to-.collapse_replacement(default true) - squashes runs of the replacement char into one, soMy///PathbecomesMy_Pathinstead ofMy___Path. Leave it on.max_length(default 255) - caps output length and preserves the extension when truncating.
The output is a single sanitized_path string. It wires straight into the filename input of whatever save node you're using.
Installing it
Via ComfyUI Manager, search "Path Sanitizer" and hit Install. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/logicalor/comfyui_path_sanitizer.git
Then restart ComfyUI. There are no model downloads and no heavy dependencies - the whole pack is one Python file and a pyproject. It's about as frictionless as a custom node gets.
Where people get burned
The big one: it sanitizes a path component, not a full path. Because / and \ are in the invalid-character set, feeding it C:/output/images/foo will happily turn the slashes into underscores. If you want a multi-folder path, run one node per segment and join them, or sanitize just the filename and keep the directory static.
A couple more gotchas worth knowing:
max_lengthis capped at 255 - matching Windows's per-component limit. You can't ask for a 500-char filename, which is honestly correct.- The replacement char is a single character. If you type
--, the node keeps only the first char (and falls back to_if even that is invalid). Feed it one char. - It doesn't lowercase by default, and it preserves spaces unless you flip
strip_spaceson. Both are toggles - handy when you're generating files to share across OSes and want to force everything to lowercase-with-no-spaces.
Is this the node you'd reach for over, say, the string utilities bundled in WAS Node Suite or Efficiency Nodes? If you already have a big utility pack installed, it probably does something similar. But if you want exactly one thing, done with no dependencies and no config, this is a clean grab. It doesn't call any API, needs no key, and can't really break your setup - the worst case is you don't need it.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | The string to sanitize for filesystem use | |
| replacement_charopt | STRING | _ | Character to replace invalid characters with |
| max_lengthopt | INT | 2551–255 | Maximum length of the sanitized path component |
| lowercaseopt | BOOLEAN | false | Convert the result to lowercase |
| strip_spacesopt | BOOLEAN | false | Remove all spaces from the result |
| collapse_replacementopt | BOOLEAN | true | Collapse consecutive replacement characters into one |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| sanitized_path | STRING | — |