Get Filename by Index
Pick a filename out of the list, same index your image came from
- file_name
The annoying thing about batch pipelines is that images lose their names. You load a folder, process the pixels, and somewhere between the VAE and the sampler the source filename just evaporates. IndexedNameSelectorNode (display name "Get Filename by Index") is the tiny node that refuses to let that happen. Feed it the name list from FolderImageLoaderNode and an integer, and it hands back the one filename at that position. That's the entire job, and it's the entire reason this node exists.
Where it earns its keep is next to IndexedImageSelectorNode. Run both with the same index value and you get the image and its original name in lockstep - which means you can save each processed result under the name of its source, and nobody has to guess what output_3849.png used to be. It's the pair that makes the pack's "per-index batch processing" story actually work.
How it works
There is no clever mechanism here, and that's the point. It takes image_name_list (the STRING list from the folder loader) and an index, checks the index is in range, and returns file_name - a single STRING. Out of bounds and it raises IndexError with a message that tells you the index and the list size. Simple, and simple is what you want in loop plumbing you'll look at at 2am.
Inputs and outputs
image_name_list- the name list output fromFolderImageLoaderNode. Required.index- INT, default 0, min 0. The position to pull.
Output: file_name (STRING). Wire it into SaveExactNameImageNode's filename, into a text preview, or into anything that wants a string.
Install
Same pack, same steps. 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
Restart ComfyUI. Dependencies: pillow, boto3, opencv-python-headless, numpy, torch (already installed with ComfyUI). No model files. Ignore the README's ComfyUI core patches unless you're setting up the AWS error reporting.
Where people get burned
- Index out of range - you indexed past the end of the list. If you're generating the index with a counter, remember the list is zero-based: the last valid index is
len(list) - 1, notlen(list). - Mismatched lists - the classic mistake is indexing a name list that doesn't line up with the image list it came from, because you loaded names from one folder and images from another. Both lists come out of the same loader, so keep them together.
- It expects a list, not a string. If you plug a single filename in here expecting it to "select" it, you'll get a confusing error. This node indexes lists.
There's no drama to this node - which is the compliment. It's the kind of unglamorous glue that batch workflows quietly depend on, and because it does one thing and does it with an explicit error message, it's easier to trust than a lot of fancier string utilities.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image_name_list | STRING | — | |
| index | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| file_name | STRING | — |