Nodes/ComfyUI-JDCN/JDCN_ReBatch
ComfyUI Node

JDCN_ReBatch

Chunk a long list of files into batches of N

By daxcayΒ·Created 2 years agoΒ·Updated about a year agoΒ· 159
JDCN_ReBatch
    • FilePaths
    β—„FileNamesβ€”β–Ί
    β—„BatchSize1β–Ί
    β—„TextListfalseβ–Ί

    Say you've scanned a folder of 120 frames and you want to process them in groups of 8 - one batch per run, or fed into a loader that takes a handful of files at a time. ComfyUI doesn't have a core node for "take this list and split it into fixed-size chunks." JDCN_ReBatch is exactly that: a list of strings goes in, and out comes the same list regrouped into batches of whatever size you ask for. It's the piece that turns "load this whole folder" into "load this folder, N files at a time."

    How it works

    The node takes your input list and chunks it front-to-back using BatchSize. If you feed it 10 items with BatchSize = 3, you get four chunks: 3, 3, 3, and a leftover 1. No padding, no wraparound - the final batch is just smaller. That "last batch is short" behavior is the thing to remember when you're doing math about how many runs a workflow will produce.

    The TextList toggle changes the shape of each output chunk:

    • False (default) - each output element is a list of the file names in that batch. In the UI it'll render as a comma-separated group.
    • True - each output element is a single string with the batch's items joined by newlines.

    Both come out of the FilePaths output, which is declared as a list of lists. Consumers that accept a list of strings will usually cope; consumers that want flat input won't.

    Inputs at a glance

    • FileNames - the list to chunk. Expects a list wire (forceInput).
    • BatchSize - 1 to 9999, default 1. The number of items per output chunk.
    • TextList - batch contents as a newline-joined string (true) or a raw list (false).

    Where it fits

    This pack is built around path-based workflows, and this node is the loop enabler. A typical animation setup: JDCN_AnyFileList scans a frames folder β†’ JDCN_ReBatch groups the paths into chunks of N β†’ a JDCN_BatchImageLoadFromList picks up one chunk per queue. The pack's latent loader (JDCN_BatchLatentLoadFromList) even has its own index-based selection for the same job, but ReBatch is the general-purpose version that works on any string list - prompts, captions, anything.

    Install

    Comes with ComfyUI-JDCN. ComfyUI Manager β†’ Install Custom Nodes β†’ search "JDCN", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/daxcay/ComfyUI-JDCN.git
    pip install -r requirements.txt
    

    Only dependency in the pack is piexif; no models.

    Gotchas

    • Empty input - an empty list prints Empty FileName to the console and returns an empty string. The run survives, your downstream does not.
    • BatchSize semantics - it's items-per-batch, not number of batches. Setting 8 when you meant "8 batches" gives you groups of 8 instead. Most people who get confused by this node are confused about that one knob.
    • Nested output - the output really is a list of chunks. If a downstream node chokes with a type error, check whether it expects the flat list or the batched one and adjust TextList accordingly.

    Small node, but it's the difference between a workflow that processes a folder in one giant memory-hungry gulp and one that chews through it in tidy, restartable chunks.

    CategoryπŸ”΅ JDCN πŸ”΅

    Inputs (3)

    NameTypeDefaultDescription
    FileNamesSTRINGβ€”
    BatchSizeINT11–9999β€”
    TextListBOOLEANfalseβ€”

    Outputs (1)

    NameTypeDescription
    FilePathsSTRINGβ€”