逐个读取图片文件 (Iterator)
Turn a folder of images into a queue ComfyUI walks through one at a time
- image
- 文件名
ComfyUI loves batches, but some workflows can't take them. Maybe your pipeline needs per-image state, or the downstream node chokes above one image at a time, or you're pairing every image with its own prompt file. This node solves that the lazy, correct way: point it at a folder and it hands out one image per queue run, walking the files alphabetically until the folder's empty. It's the "turn a folder into a queue" workhorse of the ComfyUI-iterator-nodes pack, and it's the node you'd reach for before writing a loop yourself.
How it works
The mechanism is the same across every iterator in this pack, and it's worth understanding once because it's clever and slightly weird. The node keeps state on itself - a running index, a cached list of files, and the folder path it scanned. Its IS_CHANGED method returns float("NaN"), the documented always-rerun idiom that makes ComfyUI re-execute it on every queue run no matter what (the exact trick random-picker nodes use, and a known cache-killer for everything downstream of it - fine here, that's the point).
Each run it:
- Scans the folder once for
.png,.jpg,.jpeg,.webp,.bmpand sorts the names - then caches that list so it doesn't rescan unless the path changes. - Reads the file at
index, loads it with Pillow, and hands you anIMAGEtensor shaped[1, H, W, 3]in RGB. - Bumps the index.
When the index passes the last file it resets to zero and raises an exception - ComfyUI shows it as an error, but that's the designed finish line: "all files processed, workflow terminated." It's not a crash, it's the pack's way of stopping the queue.
The inputs and outputs that matter
The node has exactly one input worth touching: folder_path - the absolute path to your image folder. The default is a Windows-style C:\path\to\your\image_folder, so paste a real path and don't panic when the backslashes look wrong on Linux or Mac (forward slashes work).
Outputs:
image(IMAGE) - the current file as a normalized[1,H,W,3]RGB tensor. Wire it anywhere you'd wire a Load Image output.文件名(STRING) - the base filename with the extension stripped (yes, it's labeled in Chinese - the author's README is bilingual). This is what you feed toFilenameComparatorto prove the image and its caption txt are in sync.
Installing it
It ships in ComfyUI-iterator-nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/GHOSTLXH/ComfyUI-iterator-nodes
then restart ComfyUI - or use ComfyUI Manager and search the pack name. No model files, no API key. Pillow and numpy ship with ComfyUI, so the image and text iterators install clean.
Where people get burned
- The queue mode thing. The README says it straight: for hands-free batch walking, set ComfyUI to "Run (on change)" queue mode. In the default run-once mode you'll click Queue once per file and it'll feel broken.
- The cached file list. Files dropped into the folder after the first scan won't be picked up until you change the path (which forces a rescan) or restart. Drop everything in before you start.
- The stop is an error. If you see red text saying all N images were processed, that's the happy path. Wire your downstream to be okay with the queue stopping there.
- Each node instance has its own counter. Duplicate the node and you've got two independent walks, not a shared one.
- No resizing. You get native-resolution frames. If your workflow assumes a fixed size, add a resize after, or you'll hit shape mismatches on your first different-sized image.
For the pairing workflow this pack is built around - image plus same-named txt prompt - grab its sibling TextFileIterator and run them in parallel with a FilenameComparator between them. That's the whole point of the pack, and it works.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| folder_path | STRING | C:\path\to\your\image_folder | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| 文件名 | STRING | — |