Nodes/Comfyui_PDuse/PD:Text Save Path
ComfyUI Node

PD:Text Save Path

Save text to numbered files without fighting ComfyUI's cache

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD:Text Save Path
    • success
    • saved_count
    text
    output_foldertext_output
    filenametext
    delimiter_
    padding1
    number_startfalse
    file_extensiontxt
    refresh_each_runfalse

    The text writer with a real filename scheme

    PDTEXT_SAVE_PATH ("PD:Text Save Path") writes text to disk with an actual file-naming system: output folder, base filename, delimiter, zero-padding, and a toggle for whether the number goes first or last. You hand it text, it produces text_001.txt (or 001_text.txt, your choice) in ComfyUI/output/text_output/, auto-incrementing so reruns never overwrite. It also tells you whether it worked and how many files it saved.

    Every generation workflow eventually needs to save its prompt, seed, or captions to a file, and ComfyUI core has no dedicated text-save node worth the name. This one slots right where you'd expect - the output conventions are the standard ones the KB's image-io-metadata.md documents: saves land under output/, and you read them back from there. If you're batch-captioning, this is the tail end of the pipeline the pack's text-list nodes feed.

    How it works

    The source resolves the output directory from ComfyUI's folder_paths.get_output_directory(), so files always land under output/ plus your output_folder (default text_output), created on the fly. The input text is split into a list three ways: if it parses as JSON and is a list, each element becomes a file; if it's multiline, each non-empty line becomes a file; otherwise it's a single file. Then it names each file per your scheme - filename_delimiter_counter.ext with padding digits, or counter-first when number_start is on - and walks the counter past anything that already exists.

    The clever bit is refresh_each_run. ComfyUI caches aggressively, and a text-save node whose inputs didn't change would otherwise be skipped. The node overrides its change detection to re-run every time when that toggle is on (it's the always-rerun trick from comfyui-node-plumbing.md). If your text never saves and you're sure the path is right, this toggle is the first thing to check.

    Inputs and outputs

    • text (required) - the content to save. Wired in from another node.
    • output_folder, filename, delimiter, padding, number_start, file_extension (txt/json/csv/log/md), refresh_each_run.
    • Outputs: success (boolean - saved at least one file) and saved_count (int).

    Installing it

    Part of Comfyui_PDuse:

    cd ComfyUI/custom_nodes
    git clone https://github.com/7BEII/Comfyui_PDuse.git
    cd Comfyui_PDuse
    pip install -r requirements.txt
    

    Or search "Comfyui_PDuse" in ComfyUI Manager and restart.

    The gotchas worth knowing

    Files land under ComfyUI/output/, not wherever you might have typed - output_folder is a subfolder name, not an absolute path, so don't expect it to write to /home/you/captions. Empty lines are skipped, which is usually what you want but can make a numbered batch come out with gaps. And the split-on-multiline behavior means a deliberately multiline single caption gets broken into several files - if your text legitimately contains newlines, feed it as a JSON-encoded string instead. Minor stuff, all of it; for a reliable numbered text sink this is one of the better ones.

    CategoryPDuse/Text

    Inputs (8)

    NameTypeDefaultDescription
    textSTRING
    output_folderSTRINGtext_output
    filenameSTRINGtext
    delimiterSTRING_
    paddingINT10–9
    number_startBOOLEANfalse
    file_extensionCOMBOtxt5 options: txt, json, csv, log, md
    refresh_each_runBOOLEANfalse

    Outputs (2)

    NameTypeDescription
    successBOOLEAN
    saved_countINT