Nodes/PortraitUtils/Filename: Append Suffix
ComfyUI Node

Filename: Append Suffix

Suffix filenames without breaking multi-part extensions

By heyburns·Created 11 months ago·Updated 4 months ago· 1
Filename: Append Suffix
    • filename
    filename
    suffix
    separator-
    strip_all_extensionstrue
    preserve_directorytrue
    trim_whitespacetrue

    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 + - + v2photo-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.gz fix: with it on, archive.tar.gz + _done becomes archive_done.tar.gz instead of archive.tar_done.gz. On is almost always what you want.
    • preserve_directory (default on) - keeps any directory prefix on the filename intact so output/foo.png stays output/foo-suffix.png rather 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's strip_all_extensions being off, or a suffix that already includes an extension. Turn the toggle on and keep suffixes extension-free.
    • Directory vanished from the result - preserve_directory got 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 separator to "" 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.

    CategoryPortraitUtils/String

    Inputs (6)

    NameTypeDefaultDescription
    filenameSTRING
    suffixSTRING
    separatorSTRING-
    strip_all_extensionsBOOLEANtrue
    preserve_directoryBOOLEANtrue
    trim_whitespaceBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    filenameSTRING