Load String From Directory
Every caption file at once
- string
- directory
- name
If you've ever looked at a folder of fifty caption files and wished you could just dump them all into ComfyUI at once, this is the node. Load String From Directory reads every .txt file in a folder and returns all their contents as parallel lists - one list of strings, one of the directory, one of the filenames - so a loop or batch consumer can walk them together.
This is the text twin of the pack's image loaders, and it slots straight into the training-adjacent workflows. The caption sidecar convention means your training data is literally image.png next to image.txt sharing a basename (see the KB's image-io doc for that convention). Load the image folder with one FairLab node, load the text folder with this one, and the name outputs line up file-for-file - which is exactly how you'd feed pairs to a captioning, tagging, or LoRA-preparation pipeline.
Inputs and outputs
directory(STRING) in - the folder to scan.string(STRING list) out - contents of each.txt, in directory listing order.directory(STRING list) out - the directory repeated per file.name(STRING list) out - each filename with the extension stripped.
All three outputs are lists of equal length, aligned by index. The name output is the one that makes pairing with an image loader trivial - 0001.png ↔ 0001.
How it works
It lists the directory, keeps only files ending in .txt, and reads each one as UTF-8. Note it does not recurse into subfolders, and it only picks up .txt - a caption or .json file won't be read. Empty directories just return empty lists rather than erroring.
Where it fits
Batch prompt loading, dataset caption ingestion, and any workflow where the text lives in files instead of widgets. It's marked as an output node, so it always runs - if you're loading a big folder every run, that's fine, but remember the reads happen on the backend machine.
Install
FairLab installs as one pack via ComfyUI Manager (search ComfyUI-FairLab) or:
cd ComfyUI/custom_nodes
git clone https://github.com/yanhuifair/ComfyUI-FairLab.git
cd ComfyUI-FairLab
pip install -r requirements.txt
Restart after. No extra dependencies needed for this node. It's under Fair/string.
Gotchas
- Path must be visible to the ComfyUI backend (the server machine), and if your ComfyUI is remote, the folder lives there, not on your laptop.
- Ordering comes from
os.listdir, which is not guaranteed sorted. If order matters, name your files so that a plain listing matches what you expect - zero-padded numbers (frame_001.txt) help a lot. - It silently skips non-
.txtfiles, so a folder mixing formats will quietly read fewer files than you think.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| directory | STRING | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |
| directory | STRING | — |
| name | STRING | — |