Nodes/ComfyUI-DataSet/DataSet_TextFilesSave
ComfyUI Node

DataSet_TextFilesSave

Write Your Caption Files Back to Disk Without Leaving the Graph

By daxcay·Created 2 years ago·Updated about a year ago· 58
DataSet_TextFilesSave
      ◄TextFileNames—►
      ◄TextFileContents—►
      â—„destinationdirectory pathâ–º
      ◄save_mode▾►
      ◄file_mode▾►
      ◄file_format▾►

      If you're prepping a training dataset, this is the node that closes the loop. Load your captions with DataSet_TextFilesLoad, mangle them with DataSet_ConceptManager or DataSet_FindAndReplace, and then write them back to a folder with DataSet_TextFilesSave - all inside one ComfyUI graph, no text editor, no copy-pasting a hundred files.

      The name undersells it slightly. It's a batch file writer that takes two parallel lists - file names and file contents - and turns them into real .txt files in whatever directory you point it at. The directory is created for you if it doesn't exist, which is one of those small things that stops being small when you're on your thirtieth run.

      The inputs that matter

      • TextFileNames - the file names (without extension; a .txt is appended for you).
      • TextFileContents - the caption text for each file, as a list.
      • destination - the folder to write into.
      • save_mode - Overwrite clobbers same-named files, Merge appends to them, SaveNew finds a unique name instead of overwriting, and MergeAndSaveNew appends then renames. SaveWithNewFormat writes using the extension you pick in file_format instead of forcing .txt.

      Two smaller widgets finish the job: file_mode lets you normalize line endings for Linux|Unix (handy if you've been writing captions on Windows), and file_format only really matters when save_mode is SaveWithNewFormat - txt or csv, with na meaning "leave it alone".

      How it works

      Under the hood it's dead simple Python - the node zips names and contents together and writes each pair. The subtlety is that InputIsList is set, so TextFileNames and TextFileContents both arrive as lists, and both are forceInput, meaning you're expected to wire them in from a loader or editor rather than type them as widgets. That's the normal shape of a pipeline: load → edit → save.

      Installing it

      It ships in the ComfyUI-DataSet pack, so it comes with all of its siblings at once:

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

      Then restart ComfyUI. Easier still: ComfyUI Manager → Custom Nodes Manager → search "DataSet" → install. The requirements file pulls in matplotlib, pandas and friends for the pack's other nodes, so the first install is a little chunky even though this node alone needs nothing beyond Python's stdlib.

      Common issues

      The one gotcha people actually hit: every file gets .txt forced onto the end of the name, even when you asked for csv in file_format - SaveWithNewFormat is the mode that honors the extension. If your CSV keeps coming out as a .txt that's why.

      Also worth knowing: Merge only appends to files that already exist, and MergeAndSaveNew is the mode that both merges and renames. The README's own author famously left "DONT UNDERSTAND THIS" in the docs next to those modes, so if you found them confusing, you're in good company. Test once on a scratch folder before pointing it at your real dataset - that's the honest recommendation for anything that writes files in bulk.

      Category🔶DATASET🔶

      Inputs (6)

      NameTypeDefaultDescription
      TextFileNamesSTRING—
      TextFileContentsSTRING—
      destinationSTRINGdirectory path—
      save_modeCOMBO5 options: Overwrite, Merge, SaveNew, MergeAndSaveNew, SaveWithNewFormat
      file_modeCOMBO2 options: Windows, Linux|Unix
      file_formatCOMBO3 options: na, txt, csv

      Outputs (0)

      No outputs