Nodes/ComfyUI-Simple-Iterator/Iterator Load Text From File
ComfyUI Node

Iterator Load Text From File

Iterate without touching the prompt box

By yangzhuangqiu·Created 5 months ago·Updated 5 months ago· 0
Iterator Load Text From File
    • TEXT
    • SOURCE_PATH
    • INDEX
    • TOTAL
    file_path
    parse_modefile_split
    delimiter\n---\n
    json_field
    encodingutf-8
    loop_modestop
    resetfalse
    enable_logfalse

    The name is the whole pitch. If you've ever hand-edited the prompt box for the 47th time while batch-generating a character sheet or an asset pack, this node is the fix: it reads one text file, splits it into chunks, and serves you one chunk per queue run. You wire its TEXT into your prompt input, hit Queue, and it walks the whole list while you do literally anything else.

    It ships in ComfyUI-Simple-Iterator, a small pack built around one idea: one sample per run iteration over files. Nothing exotic under the hood - no API calls, no hidden model downloads - but the cursor logic is the part that trips people up, so let's get into it.

    How it works

    On every execution the node parses the whole file, then asks a tiny persistence layer for the current cursor. The cursor lives in a .iterator_state.json file in the pack's folder, keyed by node id plus the file path plus your parse settings - so two copies of the node pointed at different files never fight over one cursor. That's also what beats ComfyUI's caching: the node reports a changing fingerprint each run, so the queue actually re-executes it instead of serving you a stale cached result forever.

    Three parse modes:

    • file_split (default) - splits on a delimiter, default \n---\n. A prompts file where each prompt is separated by a line containing only --- becomes one item per prompt. Escaped characters in the delimiter are honored.
    • json_array - the file must be a JSON array; each element is one item. Set json_field to a dot path like prompt.positive if your objects are nested and you only want one field.
    • jsonl - one JSON object per line, same json_field option, and SOURCE_PATH becomes file.jsonl:12 so you always know the line.

    The inputs that matter

    • file_path - the single file. Absolute path, or relative to ComfyUI's working directory.
    • parse_mode / delimiter / json_field - covered above.
    • loop_mode - stop (default) raises an error when you run out; loop wraps back to the top; hold_last keeps returning the last item. For unattended batches, keep stop.
    • reset - edge-triggered. It only rewinds when reset flips from False to True. Toggling it the wrong direction does nothing, which confuses exactly once.

    Outputs: TEXT (the current chunk), SOURCE_PATH (a marker like file.txt#3 or file.jsonl:12), INDEX (0-based), TOTAL. Wire TEXT straight into the positive or negative input of a CLIP Text Encode.

    Installing it

    Same steps as the whole pack - ComfyUI Manager, search "ComfyUI-Simple-Iterator", or clone:

    cd ComfyUI/custom_nodes
    git clone https://github.com/yangzhuangqiu/ComfyUI-Simple-Iterator
    

    Then restart ComfyUI. Dependencies are just numpy and Pillow; torch comes from your existing ComfyUI install, so nothing heavy downloads.

    Where people get burned

    "No text items found" means your delimiter never appears in the file, or the file is empty after stripping. The "Iterator exhausted" error with the default stop isn't a bug - that's the safe-stop behavior, so you never silently regenerate item zero on a rerun. And blank lines are skipped in file_split, so INDEX won't line up 1:1 with line numbers. If you need precise provenance, use jsonl and read SOURCE_PATH.

    Categorysimple_iterator

    Inputs (8)

    NameTypeDefaultDescription
    file_pathSTRING
    parse_modeCOMBOfile_split3 options: file_split, json_array, jsonl
    delimiterSTRING\n---\n
    json_fieldSTRING
    encodingSTRINGutf-8
    loop_modeCOMBOstop3 options: loop, stop, hold_last
    resetBOOLEANfalse
    enable_logoptBOOLEANfalse

    Outputs (4)

    NameTypeDescription
    TEXTSTRING
    SOURCE_PATHSTRING
    INDEXINT
    TOTALINT