Save String To Directory
Get your prompts and captions onto disk, where they belong
The FairLab Save String To Directory node writes a string to a text file at a path you choose. On its own that sounds anticlimactic - your OS has Notepad, after all. In a workflow it's the difference between your prompts vanishing with the session and having a dataset-ready folder of captions when you're done.
The two real use cases:
- LoRA training datasets. The
.captionextension in the dropdown is a direct nod to Kohya-style training, where every training image sits next to a same-named text file with its caption. A graph that generates images, interrogates them, and writes matching caption files is an actual dataset factory, and this node is the write step. - Logging what you generated. A prompt that would otherwise live only in the PNG metadata (see the KB's image-io doc on workflow-in-image) gets a plain-text sibling you can grep, diff, and feed to other tools.
How it works
The mechanism is a three-line file write: it joins directory + name + extension into a full path and writes the string with UTF-8 encoding. No frills - which is exactly what you want when the output is a training caption.
The inputs that matter
- string - the content to write. Wire it from a String node, a Show String, a translate node, or anything producing text.
- directory - the target folder. An absolute path is the safe move.
- name - the filename, without the extension. The node appends the extension for you.
- extension - a dropdown with three choices:
.txt,.cap,.caption. The last two are the training-ecosystem formats.
It's an output node with no outputs - it consumes a string and produces a file. Nothing to wire downstream.
The gotchas
- It will not create the directory. If the folder doesn't exist, you get a
FileNotFoundError. Make it first, or let Save Image To Folder's sibling pattern be your reminder to check paths before you queue. - No overwrite protection. If the file exists, it's silently replaced. Great for "regenerate the captions every run," a footgun if you didn't mean to clobber something.
- The name should be bare. Type
scene_042, notscene_042.txt- you'll getscene_042.txt.txtand your trainer will be confused. - Relative paths resolve against ComfyUI's working directory, which isn't always where you think it is. Absolute paths remove the guesswork.
Pairing it
The pack's string family is designed to compose: build a prompt with String Append and Unique Tags, verify it with Show String, translate it with String Translate, and land it on disk here. The matching Load String From Directory reads it back, so you can also round-trip - save a config string, reload it in a later session, and keep one graph as your source of truth.
Installing it
One pack, all nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/yanhuifair/ComfyUI-FairLab.git
cd ComfyUI-FairLab
pip install -r requirements.txt
Restart, or search "ComfyUI-FairLab" in ComfyUI Manager. No dependencies of its own - if the pack imported, this node is there. The failure modes are path errors at runtime, not import errors.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| directory | STRING | — | |
| name | STRING | — | |
| extension | COMBO | .txt | 3 options: .txt, .cap, .caption |
Outputs (0)
No outputs