Nodes/ComfyUI-DD-Nodes/DD TXT File Merger
ComfyUI Node

DD TXT File Merger

Turn a folder of captions into one big string for your LLM

By Dontdrunk·Created 2 years ago·Updated 21 days ago· 181
DD TXT File Merger
    • merged_text
    input_folder

    ComfyUI has never been great at "read a bunch of files." DD TXT File Merger fixes one specific version of that: it walks a folder recursively, grabs every .txt file, and merges them into a single string - each file labeled with its path so you know what came from where. One string out, ready for any LLM node, prompt builder, or caption pipeline.

    How it works

    The single input is input_folder, a plain string path on the machine running ComfyUI (important: the server's filesystem, not necessarily the machine you're browsing from). The node does os.walk over the folder and subfolders, collects every .txt, sorts them by path so ordering is stable across runs, then reads each with an encoding fallback chain - utf-8, gbk, gb2312, utf-8-sig - which matters because caption files in the wild are routinely saved in encodings that aren't UTF-8. Chinese captions especially: if you've ever opened a "UTF-8" file and gotten mojibake, you know why the author (a Chinese-speaking developer) built this in.

    Each non-empty file becomes:

    === relative/path/name.txt ===
    <file contents>
    
    

    joined with newlines. Empty files are skipped, unreadable ones are logged and skipped, and the node never crashes on a bad folder - it returns an error string as the output rather than throwing. The single output, merged_text, is a STRING.

    When you'd reach for it

    Dataset and caption work is the obvious home: dump a folder of captions into an LLM that should summarize, dedupe, or translate them in one shot. It's also handy for feeding a directory of prompts or config text into a prompt-generation workflow, and for combining loose notes into a single context blob. If you're doing LoRA prep and you've got a caption folder, this turns "read 400 files" into "wire one string."

    Installation

    cd ComfyUI/custom_nodes
    git clone https://github.com/Dontdrunk/ComfyUI-DD-Nodes
    cd ComfyUI-DD-Nodes && pip install -r requirements.txt
    

    Restart ComfyUI or use ComfyUI Manager (search "ComfyUI-DD-Nodes"). Pure Python standard library - no models, no extra deps.

    Where people get burned

    The path is server-side and literal - no ComfyUI path resolution, no drag-and-drop, no input/-relative magic. If you type C:\texts while ComfyUI runs on Linux, nothing happens (it returns an error string, not a crash). And don't point it at a folder with a million tiny files and expect speed - it's a naive recursive read, fine for hundreds of captions, sluggish for tens of thousands. The output is one big string, so if your downstream LLM has a context limit, you may need to truncate. Labels are Chinese-first; the pack ships an English locale.

    Category🍺DD系列节点/文本处理

    Inputs (1)

    NameTypeDefaultDescription
    input_folderSTRING

    Outputs (1)

    NameTypeDescription
    merged_textSTRING