ComfyUI Node

Load String

Read a text file into the graph

By yanhuifair·Created 2 years ago·Updated 3 months ago· 2
Load String
    • string
    • path
    • name
    path

    Prompts get long. Eventually one of them lives in a .txt file - a caption you wrote elsewhere, a style block you share between workflows, a character sheet you keep editing - and retyping it into a text widget every run is how you end up with drift. Load String reads one text file by path and hands you its contents on a wire, plus the path and the filename as bonuses.

    It's the single-file sibling of FairLab's Load String From Directory, and it's the one you want when the file is one file, not a folder full. Feed it an absolute path, get three outputs:

    Inputs and outputs

    • path (STRING) in - the file location on the machine running ComfyUI.
    • string (STRING) out - the file's contents, decoded as UTF-8.
    • path (STRING) out - the path you gave it, passed through.
    • name (STRING) out - the filename with extension stripped.

    Three outputs because downstream nodes often want more than the text: the name is handy for filenames, logging, or matching the file to something else in the graph.

    How it works

    Straight file I/O: open the path, read it, return. The behavior worth knowing is the failure mode - if the file doesn't exist, this node does not raise. It returns the literal string File not found: <path> as the string output and keeps going. So a typo in the path produces a silent "File not found:" string flowing into whatever consumes it, and you'll see that text rendered into a prompt or a filename before you spot the problem.

    Where it fits

    The classic setup is a "prompts" folder you keep next to your workflow: each prompt its own file, Load String pointing at the one you're using today. It also pairs naturally with the caption sidecar convention - training pairs live as image.png + image.txt sharing a basename - where reading the .txt into a node that needs the text is a much cleaner flow than copy-pasting.

    Install

    FairLab is one pack; use 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 pack-specific dependencies needed for this node. It lives under Fair/string.

    Gotchas

    • Paths are relative to the ComfyUI server, not your browser. In a local install that's the same machine; on a remote or container setup, the file must exist where the backend can see it.
    • UTF-8 only. A file saved in another encoding will read as mojibake - the pack ships a Fix UTF-8 String node for exactly that situation.
    • Remember the non-raising "File not found:" behavior. If text stops making sense downstream, check the path first.
    CategoryFair/string

    Inputs (1)

    NameTypeDefaultDescription
    pathSTRING

    Outputs (3)

    NameTypeDescription
    stringSTRING
    pathSTRING
    nameSTRING