Nodes/Batch Folder Tools/Save Text File
ComfyUI Node

Save Text File

Save captions as files — right next to the images that produced them

By hodgemann·Created 6 months ago·Updated 6 months ago· 3
Save Text File
    • saved_text
    text
    filename_stem
    output_folder
    file_extension.txt
    overwrite_existingtrue

    A VLM spits out a caption string, and then what? In a stock ComfyUI you've got nowhere to put it except a note node or a text preview that forgets everything when you close the tab. Save Text File from hodgemann's ComfyUI-BatchFolderTools is the pack's writer: it takes a text string and writes it to disk as a real file - defaulting to .txt - named after whatever image or video just produced it.

    It's the last leg of the batch captioning loop, and the least glamorous part, which is exactly why it matters. A caption that only lives on screen isn't a dataset; a caption sitting as photo_001.txt next to photo_001.jpg is. For LoRA training, that file layout is the deliverable - captioning quality is the single most impactful thing in a training set (lora-training.md § Captioning), and the community has settled on natural language for the LLM-encoder bases. This node is just the part that makes those captions survive.

    How it works

    Nothing clever. It takes the text, strips whitespace, and writes it to output_folder / filename_stem + extension as UTF-8, creating the directory if it doesn't exist. It's an output node - it has no visual output, just a console line saying where the file landed. If overwrite_existing is off and the file's already there, it prints a skip line and leaves your work alone.

    The detail that ties the whole pack together is the extension choice. The loader nodes' skip_captioned resume feature checks for .txt, .caption, and .cap files next to each source file to decide what's already done - and this node is the thing that writes those files. Save a caption with .caption, crash mid-batch, restart, flip skip_captioned on, and the loader skips every file you already finished with zero GPU cost. The save node and the resume mechanism are two halves of one workflow.

    The inputs

    • text - the string to save. Wire the caption output of your VLM here (it's a forced input, so it expects a wire, not typed text).
    • filename_stem - the base name without extension. Wire from the loader's filename_stem output. This is what makes each save land on the right file.
    • output_folder - where to write. The pack's convention is to wire the loader's folder_path here so captions save right next to their images. You can type any other path; it'll be created if missing.
    • file_extension - .txt, .caption, or .cap. .txt is the default and fine for most purposes; the .caption / .cap choices exist mainly to interoperate with the loader's skip logic and with other tooling that looks for those names.
    • overwrite_existing - default on. Leave it on for a normal batch; turn it off if you want a "never clobber my work" pass.

    The saved_text output just echoes the cleaned string back - handy if you want to chain it onward, but you can ignore it.

    Installing it

    It's part of ComfyUI-BatchFolderTools, so: ComfyUI Manager, search Batch Folder Tools, install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/hodgemann/ComfyUI-BatchFolderTools.git
    

    No models, no special dependencies. It's the same pack as the folder loaders and Queue Next, so if you already have those, this came with them.

    Where people get burned

    • Empty output_folder. It errors immediately with a message telling you to wire it from the loader's folder_path or type a path. The save node is not psychic - wire it.
    • The classic batch-captioning footgun is on the VLM side, not this node. You're wiring a captioner into a loop, and captioner-shaped nodes are exactly the category that produced the ecosystem's one big malware incident (comfyui-ecosystem.md § The Security Incident). The pack's example workflows point at ComfyUI-QwenVL-Mod, which is a separate install with its own model download. Before you add any VLM pack to this loop, glance at its repo - this is the one place a lazy install can bite you, and the loader/loop here will happily caption your whole folder with whatever you gave it.
    • Missing resume behavior. If you crash mid-batch and restart, the loader's in-memory counter resets - but anything this node already saved as .txt / .caption / .cap is detectable, which is exactly what skip_captioned uses. If you saved captions with a different extension or somewhere other than next to the source, that resume path silently won't find them.

    One workflow note: the author's example captioning workflows wire output_folder from the loader's folder_path so captions sit in the source folder. That's the right default for training data; just know that if you ever disconnect that wire, you're deciding where a few hundred small files land, and the console prints the path each time.

    Category📂 BatchFolder

    Inputs (5)

    NameTypeDefaultDescription
    textSTRINGText to save.
    filename_stemSTRINGBase filename without extension. Wire from FolderImageLoader.
    output_folderSTRINGWhere to save files. Wire from FolderImageLoader's folder_path, or type a different path.
    file_extensionCOMBO.txtFile extension.
    overwrite_existingBOOLEANtrueOverwrite if file already exists.

    Outputs (1)

    NameTypeDescription
    saved_textSTRING