Nodes/APZmedia Naming Tools/APZmedia Clean File Name Node
ComfyUI Node

APZmedia Clean File Name Node

Turn 'untitled_final_FINAL_v3_USE_THIS_ONE' into a filename your filesystem won't fight

By APZmedia·Created 2 years ago·Updated 5 months ago· 8
APZmedia Clean File Name Node
    • cleaned_text
    input_text
    replacement_char-
    invalid_chars #%&{}\\<>*?/ $!'\":@+`|=.
    prefix
    char_limit255

    This is the workhorse of the APZmedia Naming Tools pack, and honestly the first node you should drag in. ComfyUI's Save Image node will happily write a file with spaces, ?, #, or a stray $ in the name - and then the file sits there as a folder-sync error waiting to happen, or flat-out refuses to open on someone else's machine. Clean File Name Node takes whatever string you hand it and returns one that a filesystem will tolerate without passive-aggressive behavior at 3am, as the author (Pablo Apiolazza of APZmedia, a VFX-roots naming pack) puts it.

    The mechanism is straightforward and, importantly for a sanity-checking workflow, deterministic - same input, same output, every run:

    1. Accent-stripping first via the unidecode library. "Ñoño" becomes "Nono". This is the one real dependency in the whole pack, and it's why these nodes exist at all.
    2. Spaces become your replacement_char (default -).
    3. Line breaks are removed.
    4. Every character in the invalid_chars list gets swapped for the replacement char too. The default is #%&{}\<>*?/ $!'\":@+|=."- note it includes a leading space and a$`, so even the sneaky ones are covered.
    5. Runs of consecutive replacement chars collapse to one, so my file---name doesn't come out as my---file----name.
    6. Your prefix goes on the front, then the whole thing is truncated to char_limit (default 255, max 4096).

    That last step is the one beginner-facing footgun: the prefix counts toward the limit, and truncation just slices from the end. A long prefix can eat your actual filename. Keep prefixes short.

    Inputs that matter: input_text, replacement_char, invalid_chars, prefix, and char_limit - that's it, five widgets, no node wiring required. The single output is cleaned_text, a STRING you can drop straight into the filename_prefix field of a Save Image node, or chain into APZmediaGenerateFilePath to build a full path. A nice touch: if you clear replacement_char entirely it falls back to - rather than erroring.

    Install

    The quick way is ComfyUI Manager - search "APZmedia Naming Tools" and hit install. Manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/APZmedia/ComfyUI-APZmedia-cleanName-from-string
    cd ComfyUI-APZmedia-cleanName-from-string
    pip install -e .
    

    Then restart ComfyUI. There are no model files to download and unidecode is tiny, so this is one of the rare custom nodes that won't drag dependency hell in with it - something the ComfyUI community knows all too well. The node lives under the APZmedia category in the menu.

    One honest caveat: this node sanitizes, it doesn't fix semantics. It will happily turn "final v2 (FINAL).png" into "final-v2-FINAL-.png" - clean, but not smarter. That's what the industry naming nodes in this pack are for.

    CategoryAPZmedia

    Inputs (5)

    NameTypeDefaultDescription
    input_textSTRING
    replacement_charSTRING-
    invalid_charsSTRING #%&{}\\<>*?/ $!'\":@+`|=.
    prefixSTRING
    char_limitINT2551–4096

    Outputs (1)

    NameTypeDescription
    cleaned_textSTRING