Select Image by Index
The one-at-a-time index selector your folder loader is begging for
- image_list
- image
FolderImageLoaderNode hands you a list of images and a list of names, but ComfyUI's sampler chain wants one image at a time. IndexedImageSelectorNode (display name "Select Image by Index") is the bridge: give it the image_list and an integer, and it returns the single image at that position. That's it. One input list, one index, one image out.
The whole ComfyForEach pack is built on this pattern - process a folder by pulling each image out one at a time, index by index, so you can loop over an arbitrary number of files without wiring up a hundred copies of your sampler block. This node is the per-iteration grab. Its string twin, IndexedNameSelectorNode, pulls the matching filename with the same index so your output names stay meaningful.
How it works
Plain list indexing with a guardrail. It takes image_list (the IMAGE list from the folder loader) and index (INT, default 0, min 0), checks the index is inside the list, and returns image - a single IMAGE tensor. Out of bounds raises IndexError with the index and list size spelled out in the message, which is more helpful than a lot of nodes bother to be.
One thing the source makes clear: this node expects a list of per-file tensors, which is exactly what FolderImageLoaderNode produces (one tensor per file, each (1, H, W, 3)). If you feed it a single batched tensor with several frames, len() counts... frames as elements, and indexing still works per-frame - but the intended wiring is loader → selector, and the two nodes are matched to each other.
Inputs and outputs
image_list- theimage_listoutput fromFolderImageLoaderNode. Required.index- INT, default 0, min 0. Which image to grab.
Output: image (IMAGE). From here it goes into your normal encode → KSampler → decode chain.
Install
Standard for this pack. ComfyUI Manager, search ComfyForEach, or:
cd ComfyUI/custom_nodes
git clone https://github.com/pupba/Comfy_ForEach
cd Comfy_ForEach
pip install -r requirements.txt
Then restart ComfyUI. Dependencies: pillow, boto3, opencv-python-headless, numpy, and torch (which ships with ComfyUI). No model downloads. The README's patches to ComfyUI's core files are only for the AWS error-reporting side; you don't need them to use this node.
Where people get burned
- Index out of range is the whole failure mode, and it means your counter ran past
len(image_list) - 1. Check that the value drivingindexcan't exceed the list length - that's what the pack'sIsLastIndexNodeis for, to stop your loop at the end. - Plugging the loader output straight into a sampler is the other classic, and it's not this node's fault - you skipped it. The loader returns a list; samplers want a single image; that mismatch is exactly the gap this node fills.
- Zero-based, always. Index 0 is the first file. If your loop starts counting at 1 you'll skip your first image and throw an error at the end.
It's a five-line node, honestly, and that's a feature: the entire mechanism is visible in the pack's source, and the only way it can fail is loudly. For batch processing, it's the right tool - pair it with the name selector, drive both from the same index, and you've got a per-file pipeline with names intact.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image_list | IMAGE | — | |
| index | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |