Nodes/ComfyUI CoolB Nodes/CB Read Text File ⚡️
ComfyUI Node

CB Read Text File ⚡️

Pull a prompt straight out of a .txt

By CoolBreeze164·Created 29 days ago·Updated 21 days ago· 2
CB Read Text File ⚡️
    • text_content
    ◄file_pathconfigs/config1.txt►

    Why you'd want a prompt in a text file

    Because you want to edit it in a real editor, diff it, generate it with a script, or keep it in the same folder as the output it belongs to. Typing a 200-word prompt into a widget is fine until you want five variants and a git history.

    CB Read Text File takes a file path and hands you the contents as a STRING. That's it. It pairs with CB Save Text File on the writing end, and the obvious uses are prompts, config lines, and passing a value from one queued run to the next - the trick people use when they chain runs to keep VRAM clear is to write state to a text file and read it back on the next pass, precisely because nothing else survives between queues.

    One input: file_path. One output: text_content. The tooltip tells you the important part: the path is relative to your ComfyUI output folder.

    How it works, and where the README disagrees with the code

    Under the hood this is a deliberately locked-down file read. The path gets rejected outright if it's absolute, if it starts with a drive letter or UNC prefix, if it contains a null byte, or if any segment is ... Then it resolves both the base directory and your path with realpath and verifies containment with commonpath, which is segment-aware and follows symlinks - so you can't escape via a symlink either.

    Worth calling out: the pack's README describes reading "from any specified file path relative to your ComfyUI root folder." The shipped code is narrower than that, and there's a comment explaining why - the author changed it to the output directory so the node can't be pointed at custom_nodes/, user/ or models/. When README and source disagree on a pack this young, trust the source. It reads output-relative, and that's the safer behaviour anyway.

    The other thing to know: failures come back as the output. A missing file doesn't raise or turn the node red - it returns the string Error: File not found at path 'configs/config1.txt'. Which is honest, and also means a downstream prompt encoder will cheerfully use your error message as a prompt. If your generations suddenly look like error text, look here first.

    Inputs and outputs

    | | | |---|---| | file_path (STRING, default configs/config1.txt) | path relative to the ComfyUI output folder | | text_content (STRING, output) | the file's contents, or an Error: ... string |

    Installing it

    Manager → Custom Nodes Manager → search ComfyUI CoolB Nodes → Install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/CoolBreeze164/ComfyUI-CoolB-Nodes
    

    No dependencies to install - it's open() with a seatbelt. One note for macOS and Linux users: the default configs/config1.txt almost certainly doesn't exist yet. Create it, or point the widget at something real, or you'll be reading the error string and wondering why your prompt is a sentence about a missing file.

    Common issues

    "File not found" is your prompt. See above. The node never throws; it returns text. Check the returned string rather than waiting for an exception.

    Your file exists but the node says otherwise. Paths are relative to output/, not the ComfyUI root and not the custom node's folder. ComfyUI/output/configs/config1.txt is what configs/config1.txt means. There's no .., no absolute paths, no ~/.

    You edited the file and nothing changed on the next run. This node has no IS_CHANGED hook, and ComfyUI caches node outputs aggressively - core's own image loader has to declare a file-modification check for exactly this reason. Change any input on the node (even re-typing the same path counts as a new value in most cases), or just restart the server, and the new contents come through. If you're using the read-write pair as state between chained runs, keep that in mind.

    You wanted to read twenty files. It's one path per node, with no globbing and no folder listing. For a folder of captions you want a batch loader; for a numbered log you're better off with the writer's increment mode and a fixed reader path.

    Keep them organised. Since the base is output/, everything you save lands next to your generated PNGs. Use a subfolder - prompts/, configs/, logs/ - from the start; the writer creates directories for you, so it costs nothing to be tidy.

    CategoryCoolB Nodes ⚡️

    Inputs (1)

    NameTypeDefaultDescription
    file_pathSTRINGconfigs/config1.txtPath relative to the ComfyUI output folder.

    Outputs (1)

    NameTypeDescription
    text_contentSTRING—