Load Text from index πΌ π π π £π
Grab one text file out of a folder by number β prompts on tap
- text
- loaded_filename
If you've ever kept a folder of prompts as .txt files and wished you could hand one to your workflow by number instead of copy-pasting, this is the node. Load Text from index points at a directory, picks the Nth .txt file in it, and returns the contents as a STRING plus the filename it loaded. In a batch workflow that's the difference between "edit 20 prompts by hand" and "wire the index to a counter and let it run." It's a small node - there's not much to it - but it slots into prompt-variation and dataset jobs surprisingly often once you know it exists.
How it works is the whole story. Give it a directory_path, it lists every .txt file in there, sorts the list alphabetically, and returns the file at position file_index. An optional filename_filter restricts the list to files containing that text - handy when a folder mixes prompt_*.txt with notes you don't want loaded. It's case-insensitive on the filter, and it's 0-indexed like everything else in Python, so the first file is index 0.
Inputs you'll set:
directory_path- absolute path to the folder, e.g./home/you/prompts. There's no browser; paste it in.file_index- which sorted file to load, starting at 0.filename_filter- optional; only load files whose name contains this string.
Outputs: text (the full file contents) and loaded_filename (just the filename, not the path - useful for checking you loaded the right one, or for logging).
Installing it means installing the pack it ships in: ComfyUI Manager β search "BETA" or "Burgstall" β ComfyUI-BETA-Cropnodes (it was recently renamed ComfyUI-BETA-Helpernodes, either name resolves). Or:
cd ComfyUI/custom_nodes
git clone https://github.com/Burgstall-labs/ComfyUI-BETA-Cropnodes
restart ComfyUI. No models, no extra pip packages.
The sharp edges are all about what "N/A" means. The node returns an empty string and "N/A" for the filename when the directory doesn't exist, there are no .txt files, the filter matches nothing, or the index is out of range - then it prints a warning to the console. So an empty text output is not a signal you loaded an empty file; it's a signal something upstream is wrong, and the console print is where you find out which. And because the sort is alphabetical, "prompt 10" sorts before "prompt 2". If your files are numbered, zero-pad them (prompt_01, prompt_02) or the index won't match your mental ordering. That's the one trap that actually bites.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| directory_path | STRING | β | |
| file_index | INT | 0 | β |
| filename_filteropt | STRING | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| text | STRING | β |
| loaded_filename | STRING | β |