Nodes/ComfyUI-JDCN/JDCN_TXTFileSaver
ComfyUI Node

JDCN_TXTFileSaver

Write text to a .txt file anywhere, with merge and overwrite modes

By daxcayΒ·Created 2 years agoΒ·Updated about a year agoΒ· 159
JDCN_TXTFileSaver
      β—„contentβ€”β–Ί
      β—„file_nameβ€”β–Ί
      β—„directorydirectory pathβ–Ί
      β—„modeβ–Ύβ–Ί

      ComfyUI will happily generate text all day - captions, prompts, batch logs - but it won't write any of it to a file you choose unless a node does it for you. JDCN_TXTFileSaver is that node: it takes any string, writes it to a .txt file at whatever directory you point it at, and gives you four modes for what to do when the file already exists. It's the text sibling of the pack's ImageSaver, and the two together are how you get ComfyUI to hand you artifacts in your own folders instead of the default output pile.

      How it works

      Feed it content (the text to save) and file_name (the base name - the node appends .txt itself, so don't type the extension). Point directory anywhere on disk; if the folder doesn't exist, it's created. Then choose mode, which decides the collision behavior:

      • SaveNew - if the file exists, it appends _1, _2, etc. until it finds a free name. Nothing is ever overwritten.
      • Overwrite - replaces an existing file with the same name.
      • Merge - appends the new content to the end of the existing file.
      • MergeAndSaveNew - reads the existing content, prepends the new text, and saves the combined result under a fresh numbered name. Original stays untouched.

      There are no outputs - it's a terminal node, the job is done when the file hits disk. If the same file name is used and it doesn't exist yet, it just writes a new file regardless of mode, so the modes only matter once a file is actually there.

      Where it fits

      • Exporting the current prompt to a sidecar text file alongside a batch of renders.
      • Logging what each queue run actually used (model, seed, prompt) to a growing file with Merge.
      • Writing caption or tag text for dataset prep - the LoRA-training crowd lives and dies by image.txt sidecars, and pairing this with JDCN_ListToString (to flatten a list) or JDCN_TagManipulatorByImageNames (same pack) covers the write side.

      Install

      Comes with ComfyUI-JDCN. ComfyUI Manager β†’ Install Custom Nodes β†’ search "JDCN", or:

      cd ComfyUI/custom_nodes
      git clone https://github.com/daxcay/ComfyUI-JDCN.git
      pip install -r requirements.txt
      

      Only pack dependency is piexif. No models, no downloads.

      Gotchas

      • Don't type the extension - file_name gets .txt appended unconditionally. Give it captions and you get captions.txt; give it captions.txt and you get captions.txt.txt.
      • Merge isn't newline-safe - appended content is glued to the end of whatever's there. If your entries should be on separate lines, include the newline in the content string yourself.
      • Mode drift - the four modes are distinct, and "Merge" vs "MergeAndSaveNew" are easy to mix up when you're tired. Merge edits the original in place; MergeAndSaveNew always produces a new file. Decide which you want before a long batch run, because both are silent about what they did.
      CategoryπŸ”΅ JDCN πŸ”΅

      Inputs (4)

      NameTypeDefaultDescription
      contentSTRINGβ€”
      file_nameSTRINGβ€”
      directorySTRINGdirectory pathβ€”
      modeCOMBO4 options: Merge, Overwrite, SaveNew, MergeAndSaveNew

      Outputs (0)

      No outputs