Nodes/ComfyUI-Batch-Process/TXT Batch Loader
ComfyUI Node

TXT Batch Loader

Feed a per-image prompt file for every image in your batch

By Zar4X·Created about a year ago·Updated 10 days ago· 16
TXT Batch Loader
    • content
    • filename
    directory
    search_title
    search_content
    delimiter
    modeincremental_text
    seed0
    filename_option
    start_index0
    end_index0
    reset_on_queue1

    People have been asking how to process a folder of images where each image gets its own prompt since ComfyUI was young - it's one of the oldest recurring requests in the community. TXT Batch Loader is the clean answer to that exact workflow: it reads a folder of text files, hands you one file's contents per queue run, and advances to the next file every execution. Wire its content output into your positive prompt, pair it with Image Batch Loader walking the matching images, and each queue run generates image #1 with prompt #1, image #2 with prompt #2, and so on. That single pattern is why this node exists.

    It's part of Zar4X/ComfyUI-Batch-Process, and it shares the loader DNA of its siblings: same directory-scan caching, same natural sort, same 1-based index range slicing, same reset_on_queue loop control.

    How it works

    directory points at a folder of .txt files. The node reads them in, and on each execution returns the next file's text through content and its name through filename (extension stripped). Modes are single_text, incremental_text, and random (seeded), and - same as the image loader - single and incremental both advance through the list in the current code, so don't lose sleep over the distinction.

    The inputs that matter

    • directory - required path to the text folder.
    • search_title + filename_option - filter which files count, exactly like the Image Batch Loader: match against the whole name, prefix, suffix, both, or neither. Only applies when search_title is non-empty.
    • search_content - this one's the party trick: it filters files by what's inside them. It's a case-insensitive literal substring match, not regex, so search_content: "cat" keeps only the prompt files that mention "cat". Great for splitting a prompt folder by topic.
    • start_index / end_index - 1-based range selection if you only want files 5–20.
    • reset_on_queue - leave it alone during a batch run; flip it 0→1 to restart from the first file.

    Two outputs: content (the full text of the file, UTF-8) and filename. Both feed wherever they need to go - content into a CLIP Text Encode or a saver's contents, filename into a prefix.

    Installing it

    Same as the rest of the pack. In ComfyUI Manager search ComfyUI-Batch-Process, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Zar4X/ComfyUI-Batch-Process
    

    Restart ComfyUI. No models, no extra deps beyond what ComfyUI already ships.

    Where people get burned

    Same empty-folder trap as its image sibling: no matching files means no exception, so check the console for "No matching txt files found" and verify your path and filters before blaming your prompt. Also remember the wrap-around - incremental mode cycles back to the first file once the queue passes the end, which is usually what you want for a long-running loop but will look like a bug the first time you see it. One more: the content filter is case-insensitive and literal, so if you're used to regex-flavored search you'll be surprised it can't do ^(cat|dog)$. That's by design - keep it simple.

    CategoryBatch Process

    Inputs (10)

    NameTypeDefaultDescription
    directorySTRING
    search_titleSTRING
    search_contentSTRING
    delimiterSTRING
    modeCOMBOincremental_text3 options: single_text, incremental_text, random
    seedINT00–18446744073709550000
    filename_optionCOMBO5 options: filename, prefix, suffix, prefix & suffix, prefix nor suffix
    start_indexINT00–999999Start index (1-based). Use 0 to start from beginning, or set 1 for first text file, 2 for second text file, etc.
    end_indexINT00–999999End index (inclusive, 1-based). Use 0 to include all remaining text files, or set >0 to limit range (1=first, 2=second, etc.).
    reset_on_queueoptINT10–1Any change to this value (0↔1) resets the read index to start from the first file again. Keep unchanged during a queue run to advance normally.

    Outputs (2)

    NameTypeDescription
    contentSTRING
    filenameSTRING