Load Prompt from TXT
Give it an index, it hands back the matching prompt — the key to per-image prompt folders
- prompt
Here's the workflow this node exists for: you have a folder of reference images, each with a matching .txt file holding that image's prompt. You want to loop through them so each image gets generated with its own prompt, automatically, without hand-editing a text node between runs. Load Prompt from TXT is the lookup half of that loop: feed it an index, it goes into your folder, finds the image at that index, and returns the text of the same-named .txt file.
It's meant to sit downstream of the pack's Interval Image Counter, which passes images through and reports which one you're on. That count value becomes the index here, and the two nodes together give you the folder traversal the whole pack is built around - one workflow that walks a directory of image + prompt pairs, generating each in turn.
How it works
Give it directory (an absolute path to a folder) and index. It lists the image files in that folder - only .png, .jpg, .jpeg, .bmp, and .webp - then natural-sorts them, which is the important detail: it sorts by numeric chunks, so image2 comes before image10, unlike a dumb lexicographic sort. It picks image_files[index], strips the extension, and reads the file named the same but with .txt. So the pairing rule is simple: your txt files must be named exactly like their images - ref_01.png pairs with ref_01.txt.
If there's no matching txt, or the index is out of range, it returns an empty string and prints a warning to the ComfyUI console. It doesn't crash, it just hands you nothing - which is honestly the right behavior for a loop that might overrun its folder.
The trigger input is an INT, and it exists for the same caching reason as every other node in this pack: if only index changes, ComfyUI will still re-execute, but wiring the counter's value into trigger too makes sure the node is treated as dirty every run. The README recommends feeding the counter into both index and trigger. Do that.
Inputs and outputs
Required: directory (STRING, default C:\), index (INT), trigger (INT). Output: prompt, a STRING with the txt file's contents (whitespace-trimmed). Wire it into a CLIP Text Encode and you're done - that run generates with whatever prompt the folder says.
One caveat the author is upfront about: the README says path handling is Windows-only and that Linux users are on their own. Looking at the code, it's plain os.listdir and os.path.join, which are cross-platform - but the author has explicitly not tested or vouched for Linux, so treat that as "works, but unverified" and test your own paths.
Installing it
It's part of the ComfyUI-Counternodes pack - one install gets all six nodes. ComfyUI Manager: search ComfyUI-Counternodes, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/GHOSTLXH/ComfyUI-Counternodes
No models to download, no extra Python dependencies.
Gotchas
First, the naming rule - if your images and txt files don't share exact names, you'll get empty prompts and won't know why until you check the console. Second, the natural-sort order is what index means: the first entry in sorted order is index 0, so make sure your files sort the way you expect. Third, the folder must contain the images, not just txt files - the node indexes off the image list, so a txt-only folder returns nothing. It's a small node with a very specific job, but for the image-and-prompt folder loop it's the piece that actually makes the traversal work end to end.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| directory | STRING | C:\ | — |
| index | INT | 00–10000 | — |
| trigger | INT | 00–9999999999 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| prompt | STRING | — |