LoadText
Read a text file from ComfyUI's folders — and get a flag for whether it existed
- STRING
- BOOLEAN
LoadText is the file-reading half of a small text-IO pair that chaojie bundled into the DragAnything pack. It's not about dragging anything - it's plumbing for the pack's infinite-video loops, where one iteration needs to pick up state that a previous iteration wrote to disk.
The two outputs are the whole story: a STRING with the file's contents, and a BOOLEAN that's True when the file actually existed. That boolean is easy to ignore and genuinely useful - in a loop you often want to branch on "is there a trajectory file yet?" before running the next clip. If the file is missing, you get ("", False), so you can detect first-run without crashing.
How it works
You pick a root_dir from an enum (input, output, or temp) and type a file name. The pack maps those three roots to ComfyUI's real input/output/temp directories via a small config file (text_file_dirs.json), which globs *.txt under each. It reads the file with Python's plain open(), so no special encoding handling - keep it to text.
The clever bit is IS_CHANGED, which is keyed to the file's modification time. That's what makes the node loop-friendly: ComfyUI re-executes it when the file on disk changes, so a workflow that writes a new trajectory file each pass (via the companion SaveText node) automatically picks up the new contents on the next pass. The default filename is the oddly specific dragtest_1.txt, which should tip you off that this node exists mainly to service the author's own drag-test loops.
Install
Same story as the rest of the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/chaojie/ComfyUI-DragAnything.git
cd ComfyUI-DragAnything
pip install -r requirements.txt
restart, done. Or install "ComfyUI-DragAnything" through ComfyUI Manager.
Gotchas
Two real ones. First, the pack also ships a SaveText node, and there's a known class-name collision: ComfyUI Manager has flagged SaveText from this pack conflicting with SaveText from ComfyUI-nodes-hnmr. If you have both, one overwrites the other depending on import order - worth knowing before you chase a mysterious "text never saved" bug. Second, the root_dir values are an enum, not a text field, so you can't type an arbitrary path; you're limited to the three configured roots. If your file lives elsewhere, put a .txt in input/ and point at it - that's what the config is for.
One more tip: the BOOLEAN output is a clean way to avoid the classic missing-file error. Rather than wiring a raw string into something that expects content, gate on the boolean and you'll get a readable graph instead of a silent empty pass.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| root_dir | COMBO | output | 3 options: input, output, temp |
| file | STRING | dragtest_1.txt | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |
| BOOLEAN | BOOLEAN | — |