ComfyUI Node

Load Txt

Pull prompts out of .txt files — with an encoding guesser that actually tries

By 1hew·Created about a year ago·Updated 7 days ago· 33
Load Txt
    • text
    • filename
    file
    encodeauto
    index0
    include_subdirfalse

    Text files are how a lot of people manage prompt libraries - a folder of curated prompts, one per file, ready to swap in and out of workflows without editing the graph. Stock ComfyUI is oddly bad at this: there's no first-class "read a text file" node in the core set, so people kludge together loaders or paste text in by hand. This node is the missing piece: point it at a .txt file (or a folder), and it hands you the contents as a string, plus the filename.

    Added in the pack's v3.5.0 release alongside a Save Txt, it's the kind of IO plumbing that sounds boring and turns out to be the thing you build a workflow library around.

    How it works

    Give it a file path. It resolves relative paths against ComfyUI's input, output, and temp directories (drag-and-drop a file and it lands in input, which is why that works), and:

    • If file points at a single .txt, it reads that.
    • If it points at a folder, it lists the .txt files inside, and index picks which one (negative indexes wrap around from the end). Set include_subdir to scan subfolders too.

    The standout feature is encode - default auto. Because this pack's author writes for a bilingual Chinese/English audience, the auto mode tries UTF-8, UTF-8-BOM, GBK, and UTF-16 in sequence before falling back. If you've ever opened a prompt file from a Chinese tutorial and gotten mojibake in your sampler, you know exactly why this matters. You can also force a specific encoding from the dropdown.

    Outputs are text (the file contents as a string - wire it into your prompt/positive/negative inputs) and filename (the file's stem, so you can display or condition on which prompt is loaded). It also shows a text preview on the node, and it caches by file mtime + size via IS_CHANGED, so editing the file on disk re-runs the node without a manual refresh.

    Where you'd use it

    Prompt-library management, mostly: a folder of curated prompts, index as a selector, and the text output straight into your conditioning. It's also handy for loading negative-prompt blocks, style lists, or any configuration you keep as plain text. If you're building a "batch of prompts from a folder" loop, this plus the pack's batch/list nodes gives you a clean way to iterate files one at a time.

    Installing it

    Part of 1hewNodes. ComfyUI Manager → search "ComfyUI 1hewNodes" → install → restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/1hew/ComfyUI-1hewNodes
    

    Restart ComfyUI. No special dependencies, no model downloads.

    Common issues

    If you get a "Txt file not found" error, the path isn't resolving - remember non-absolute paths are anchored to ComfyUI's input/output/temp folders, so drop the file where the drag-and-drop puts it. Folder mode with include_subdir off silently ignores nested files, which trips people up once they reorganize into subfolders. And while auto encoding is impressively tolerant, a truly broken file just falls back to replacement characters - the text will load but be garbage, so keep your source files in a clean encoding.

    Category1hewNodes/io

    Inputs (4)

    NameTypeDefaultDescription
    fileSTRING
    encodeCOMBOauto5 options: auto, utf-8, utf-8-sig, gbk, utf-16
    indexINT0-8192–8192
    include_subdirBOOLEANfalse

    Outputs (2)

    NameTypeDescription
    textSTRING
    filenameSTRING