Nodes/Santodan Random LoRA Node/Split Batch With Prefix
ComfyUI Node

Split Batch With Prefix

Un-batch images into individually named saves

By Santodan·Created about a year ago·Updated 2 months ago· 28
Split Batch With Prefix
  • images
  • image
  • name
subfolder
filename_SDXL_
index0

ComfyUI renders a batch of N images as one IMAGE tensor with N frames, and a stock SaveImage saves them all in one go - which is fine until you want each image saved under its own index-based filename, or fed through something that works one image at a time. Split Batch With Prefix takes that batch and hands it out one image per queue run, each named with an incrementing index plus your chosen prefix.

The concrete use case from the README: you have a 5-image batch, and you want the results named 0-SDXL_, 1-SDXL_, 2-SDXL_, … so every image lands with a matching index instead of a pile of timestamped files. It's a batch-unpacker for people who care about filenames.

How it works

The node is stateful. Each execution it looks at the batch tensor, takes the image at its current position (wrapping with modulo), and returns that single image plus a computed name. The position advances every call.

The name is built as {global_index + index}{filename} - where index is your starting offset, filename is the prefix (default _SDXL_), and the counter increments each run. If you set subfolder, it becomes {subfolder}/{counter}{filename}, and the subfolder supports a %date:yyyy-MM-dd% placeholder that expands to today's date.

The state resets when it detects a "new run": if index, filename, or subfolder change, or if the previous call was more than a second ago (a time-window heuristic so separate queue runs don't keep counting from a stale position). Same params, quick successive runs → continuous counting.

Inputs / outputs

  • images (required) - an IMAGE batch tensor (e.g. straight from KSampler or a batch builder).
  • subfolder - output subfolder path (supports %date:yyyy-MM-dd%).
  • filename - the prefix that follows the index (default _SDXL_).
  • index - starting number for the counter (default 0).
  • Outputs: image (one image, for a SaveImage node) and name (the computed filename string, matching what SaveImage will produce given the same subfolder/filename).

Gotchas

  • One image per queue run, not one per batch. If you want all five split in a single queue run, this isn't it - the point is to pair each image with a per-run index and a SaveImage. Loop or re-queue machinery in your graph drives the stepping.
  • The "new run" detection is a 1-second timer. Keep your calls inside a second and it counts up continuously; let more than a second pass between executions and it resets to the start. That's a heuristic, so very slow steps (huge upscales) can reset the counter mid-batch. If filenames come out wrong, that's usually why.
  • Name only matches SaveImage if you keep the convention. Give SaveImage the same subfolder and filename, and the file that lands on disk matches the name string output. Change one and they diverge.
  • It throws on non-image tensors. It expects [B,H,W,C]; feeding it a latents or conditioning tensor is a hard error, not a silent pass-through.

Install

ComfyUI Manager (search "Santodan"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/Santodan/santodan-custom-nodes-comfyui

Restart. No dependencies, no downloads.

CategorySantodan/utils

Inputs (4)

NameTypeDefaultDescription
imagesIMAGE
subfolderSTRING
filenameSTRING_SDXL_
indexINT00–9999

Outputs (2)

NameTypeDescription
imageIMAGE
nameSTRING