Filename: Append Suffix
Suffix filenames without breaking multi-part extensions
- filename
Renaming files sounds trivial until the file is scan.old.2021.png and you want to append _restored without producing scan.old.2021_restored.png and without mangling the directory path. This node is the boring-but-correct string tool for exactly that: append a suffix to a filename safely, handling multi-part extensions and paths the way you'd want.
Inputs are filename, suffix, separator, and three toggles. suffix is what gets added; separator (default -) goes between the base name and the suffix, so photo + - + v2 → photo-v2.png. The toggles:
strip_all_extensions(default on) - removes every trailing extension segment before appending, not just the last one. This is the.tar.gzfix: with it on,archive.tar.gz+_donebecomesarchive_done.tar.gzinstead ofarchive.tar_done.gz. On is almost always what you want.preserve_directory(default on) - keeps any directory prefix on the filename intact sooutput/foo.pngstaysoutput/foo-suffix.pngrather than becoming a bare name.trim_whitespace(default on) - strips stray whitespace around the pieces so a suffix typed with a trailing space doesn't silently corrupt the name.
The single output is the finished filename string, ready to feed into SimpleImageSaver or any save node that takes a filename. It's pure string math - no files are touched, nothing is written, it just returns a name. That's actually a relief in ComfyUI, where every save node has its own idea of what "suffix" means and several will happily produce name..png or name- -x.png if you blink.
Install
Part of PortraitUtils - Manager → search "PortraitUtils", or:
cd ComfyUI/custom_nodes
git clone https://github.com/heyburns/PortraitUtils
Restart after. It's a stdlib os.path/string helper, so no dependencies beyond the pack itself.
Common issues
- Extension ends up duplicated -
file.png.png. That'sstrip_all_extensionsbeing off, or asuffixthat already includes an extension. Turn the toggle on and keep suffixes extension-free. - Directory vanished from the result -
preserve_directorygot switched off. If you're feeding the output to a saver that expects a bare name, that might be intentional; otherwise leave it on. - Suffix glued to the name with no separator - set
separatorto""on purpose, or change it to_/-as you prefer. There's no magic here.
A one-line utility, sure. But "append a suffix without corrupting the filename" is the kind of bug that only shows up on run 47 of a batch, and this removes the whole category.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| filename | STRING | — | |
| suffix | STRING | — | |
| separator | STRING | - | — |
| strip_all_extensions | BOOLEAN | true | — |
| preserve_directory | BOOLEAN | true | — |
| trim_whitespace | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| filename | STRING | — |