Iterator Load Text From File
Iterate without touching the prompt box
- TEXT
- SOURCE_PATH
- INDEX
- TOTAL
The name is the whole pitch. If you've ever hand-edited the prompt box for the 47th time while batch-generating a character sheet or an asset pack, this node is the fix: it reads one text file, splits it into chunks, and serves you one chunk per queue run. You wire its TEXT into your prompt input, hit Queue, and it walks the whole list while you do literally anything else.
It ships in ComfyUI-Simple-Iterator, a small pack built around one idea: one sample per run iteration over files. Nothing exotic under the hood - no API calls, no hidden model downloads - but the cursor logic is the part that trips people up, so let's get into it.
How it works
On every execution the node parses the whole file, then asks a tiny persistence layer for the current cursor. The cursor lives in a .iterator_state.json file in the pack's folder, keyed by node id plus the file path plus your parse settings - so two copies of the node pointed at different files never fight over one cursor. That's also what beats ComfyUI's caching: the node reports a changing fingerprint each run, so the queue actually re-executes it instead of serving you a stale cached result forever.
Three parse modes:
file_split(default) - splits on a delimiter, default\n---\n. A prompts file where each prompt is separated by a line containing only---becomes one item per prompt. Escaped characters in the delimiter are honored.json_array- the file must be a JSON array; each element is one item. Setjson_fieldto a dot path likeprompt.positiveif your objects are nested and you only want one field.jsonl- one JSON object per line, samejson_fieldoption, andSOURCE_PATHbecomesfile.jsonl:12so you always know the line.
The inputs that matter
file_path- the single file. Absolute path, or relative to ComfyUI's working directory.parse_mode/delimiter/json_field- covered above.loop_mode-stop(default) raises an error when you run out;loopwraps back to the top;hold_lastkeeps returning the last item. For unattended batches, keepstop.reset- edge-triggered. It only rewinds whenresetflips from False to True. Toggling it the wrong direction does nothing, which confuses exactly once.
Outputs: TEXT (the current chunk), SOURCE_PATH (a marker like file.txt#3 or file.jsonl:12), INDEX (0-based), TOTAL. Wire TEXT straight into the positive or negative input of a CLIP Text Encode.
Installing it
Same steps as the whole pack - ComfyUI Manager, search "ComfyUI-Simple-Iterator", or clone:
cd ComfyUI/custom_nodes
git clone https://github.com/yangzhuangqiu/ComfyUI-Simple-Iterator
Then restart ComfyUI. Dependencies are just numpy and Pillow; torch comes from your existing ComfyUI install, so nothing heavy downloads.
Where people get burned
"No text items found" means your delimiter never appears in the file, or the file is empty after stripping. The "Iterator exhausted" error with the default stop isn't a bug - that's the safe-stop behavior, so you never silently regenerate item zero on a rerun. And blank lines are skipped in file_split, so INDEX won't line up 1:1 with line numbers. If you need precise provenance, use jsonl and read SOURCE_PATH.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| file_path | STRING | — | |
| parse_mode | COMBO | file_split | 3 options: file_split, json_array, jsonl |
| delimiter | STRING | \n---\n | — |
| json_field | STRING | — | |
| encoding | STRING | utf-8 | — |
| loop_mode | COMBO | stop | 3 options: loop, stop, hold_last |
| reset | BOOLEAN | false | — |
| enable_logopt | BOOLEAN | false | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| TEXT | STRING | — |
| SOURCE_PATH | STRING | — |
| INDEX | INT | — |
| TOTAL | INT | — |