Nodes/ComfyUI-iterator-nodes/比较文件名 (Comparator)
ComfyUI Node

比较文件名 (Comparator)

The guardrail that catches mismatched image/prompt pairs before you waste a run

By GHOSTLXH·Created about a year ago·Updated about a year ago· 7
比较文件名 (Comparator)
    • filename
    filename_a
    filename_b

    You've done the classic thing: a folder of img_042.png files and a folder of matching img_042.txt captions, and a batch workflow that processes them as pairs. Then you get fifty images in and discover image 042 got paired with prompt 043. This node is the cheap insurance against that. It's a two-input assert: filename_a and filename_b in, and if they don't match, it kills the queue with an error before you've burned a run on garbage pairs. The author's own framing says it best - "you wouldn't want to put in a lot of effort only to realize it was all in vain, right?"

    How it works

    It's about as simple as a ComfyUI node gets. Two STRING inputs, both marked forceInput, which means you can't type into them - they have to be wired from upstream nodes. That's deliberate: it's a flow-control node, not a text box. When it runs, it compares the strings:

    • Match → it passes filename_a straight through its filename output, and the workflow continues.
    • Mismatch → it raises ValueError, ComfyUI halts the queue, and you see the mismatch in the console.

    The filename output is meant to be wired into a save node's filename input, so the filename that actually gets saved is the one that just passed the check.

    Where it fits in the pack

    It's the glue for the pack's flagship pattern: run ImageFileIterator (which outputs 文件名, the base name without extension) next to TextFileIterator (same 文件名 format), and wire both into this node. Because both iterators strip extensions, the comparison is apples-to-apples - and any file that's missing its pair trips the gate instantly instead of silently misaligning everything downstream.

    Installing it

    It ships in ComfyUI-iterator-nodes, and there's nothing special about the install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/GHOSTLXH/ComfyUI-iterator-nodes
    

    then restart ComfyUI - or just use Manager and search "ComfyUI-iterator-nodes". No models to download, and no extra Python deps for this node; it's pure string comparison.

    The gotcha that gets people

    Because it compares raw strings, feed it consistent inputs. If you wire a filename with an extension into filename_a and the iterator's extension-free 文件名 into filename_b, it will fail every single time - which is confusing because the pair "looks" right. Both iterators output base names with no extension, so wire those to each other. And remember the wider pack rule: it only auto-advances in ComfyUI's "Run (on change)" queue mode, and the "all files processed" exception at the end of a folder walk is the designed stop, not a crash.

    That's the whole node. It won't sort, rename, or fix anything - it just refuses to let a mismatched pair slip through, which for a folder-batch workflow is worth having on its own.

    Categoryutilities/logic

    Inputs (2)

    NameTypeDefaultDescription
    filename_aSTRING
    filename_bSTRING

    Outputs (1)

    NameTypeDescription
    filenameSTRING