Nodes/Comfyui_PDuse/PD保存文本(路径+文件名)
ComfyUI Node

PD保存文本(路径+文件名)

Writing a list of captions out to individually named text files

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD保存文本(路径+文件名)
    • status_message
    • saved_count
    output_directory
    text_list
    filename_text

    You've got a list of caption strings sitting on a wire in your workflow and you want them out of the graph and onto disk as individual files - 10_R.txt, 11_R.txt, 12_R.txt. That's this node. It takes a text list, a multi-line list of filenames, and a directory, and writes each caption to its matching file, UTF-8, in order. The display name is Chinese - "PD保存文本(路径+文件名)", save text (path + filename) - which matches its real parentage: it's the save half of a batch-captioning pipeline, built to pair with the pack's folder text loader.

    The pairing is worth spelling out, because that's the actual use case: load a folder of .txt captions (or generate a batch of captions from an auto-tagger), edit them in the graph, then save them back with their original names. It's dataset work, and it's the rare node that does the tedious part of it.

    How it works

    filename_text is a multi-line string, one filename per line - not a list. The node splits it on newlines and zips it against text_list by index: filenames[0] gets text_list[0], and so on. A few behaviors from the source:

    • It auto-appends .txt if a filename has no extension.
    • Files are written UTF-8, so Chinese captions survive.
    • If the filename count and text count don't match, it saves the minimum count and reports the mismatch as a warning - it doesn't error.
    • The output directory is created if it doesn't exist; a missing or empty directory is a returned error string.

    The pairing semantics are why the "path + filename" name exists: the node's output tells you both where it wrote and how many files it wrote.

    The inputs that matter

    • output_directory - where to write. Required.
    • text_list - the caption contents. This is a list-type input; feed it from a list output (the pack's text nodes and loaders emit these).
    • filename_text - multi-line string, one filename per line.

    Outputs: status_message (a summary with failure list) and saved_count (INT, the number actually written).

    Installing it

    Part of Comfyui_PDuse by 7BEII. ComfyUI Manager (search "PDuse") or:

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

    Restart. No models; pack deps are numpy, Pillow, scipy, opencv-python, torchvision. Docs are Chinese-first.

    Where people get burned

    The filename input is not a list - if you connect a list output straight into filename_text, the node flattens it to a multi-line string for you (it warns and joins with newlines), but the safer habit is feeding it a text block. Second, the min-count behavior on mismatch: if your filenames list has 5 lines and your text list has 7 items, files 6 and 7 silently never get written - check saved_count against what you expected. Third, it overwrites files with the same name without asking, which is what you want for idempotent captioning but fatal if you point it at the wrong folder. Backup, then trust the report.

    CategoryPDuse/Text

    Inputs (3)

    NameTypeDefaultDescription
    output_directorySTRING
    text_listSTRING
    filename_textSTRING

    Outputs (2)

    NameTypeDescription
    status_messageSTRING
    saved_countINT