Nodes/comfyui-timesaver/TS Batch Write
ComfyUI Node

TS Batch Write

Get your results on disk before the batch finishes

By AlexYez·Created 2 years ago·Updated about 16 hours ago· 11
TS Batch Write
  • image
  • text
text
index0
total1
modeOne file, blocks
output_path
name
prefix_with_namefalse

Batches are great until they die at item 90. If you're captioning 300 images and your "save everything at the end" plan loses the whole run to one crash near the finish line, you'll want this node. TS Batch Write appends each result to disk the moment it's ready - a batch that dies at item 90 leaves 89 results on disk rather than nothing. That's the whole pitch, and for dataset work it's worth wiring up on its own.

The inputs that matter

  • text - the result for this item: a caption, a prompt, anything. This is what lands on disk.
  • index - position of this item. Index 0 starts the file from scratch; anything else appends. That single rule is what makes a resumed run (TS Batch Source's start_at > 0) add to the existing file instead of wiping it.
  • total - how many items the batch has. Drives the progress bar.
  • mode - the layout, below.
  • output_path - the target file in "one file" mode, the target folder in "per item" mode. The node refuses to guess; leave it empty and you get a plain error.

Three optional inputs round it out: name names this item's .txt (usually fed from TS Batch Load Image's name output, so the caption sits beside its picture), prefix_with_name puts the item's name in front of the result in one-file modes, and image - connect it and the current result shows on the progress bar as each item finishes. That last one matters more than it looks: ComfyUI collects normal UI previews and only sends them after the whole batch, so without it you're watching a progress bar crawl blind.

Three layouts, one of them closes a loop

  • One file, blocks - results separated by a blank line. This is what TS Batch Prompt Loader reads back.
  • One line per item - collapses each result to a single line. Read back by TS Batch Source in "Lines in text file" mode. This is how a file of captions becomes a file of generation jobs with no conversion. The collapsing isn't a style choice, it's the contract: the model answers in paragraphs whenever it feels like it, and a two-line answer in a "one line per item" file silently gains an item for whatever reads it back.
  • One .txt per item - names each file after its picture (photo.jpgphoto.txt), the layout caption datasets expect and the one LoRA training workflows actually want.

The output is a pass-through text - the same string comes out so the chain can keep going after the write. Handy if you want to write and keep processing.

Install & troubleshooting

Ships in comfyui-timesaver (AlexYez). ComfyUI Manager → search Timesaver → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/AlexYez/comfyui-timesaver
cd comfyui-timesaver
python -m pip install -r requirements.txt

Then restart ComfyUI fully (not just refresh the tab; on Windows portable use python_embeded\python.exe for pip). This node needs no models and no heavy dependencies - it's a file writer.

The only error you're likely to see is "No output_path given." - and the fix is exactly what it says. One behavior worth knowing before a re-run: because index 0 truncates, a fresh run never silently continues the previous one's file; any other index appends. So wire index and total from TS Batch Source, name from TS Batch Load Image, and you've got the classic TS Batch Source → TS Batch Load Image → model → TS Batch Write dataset pipeline with checkpoints on disk the whole way.

CategoryTS/Files

Inputs (8)

NameTypeDefaultDescription
textSTRINGThe result for this item — a caption, a prompt, any text.
indexINT00–1000000Position of this item. Index 0 starts the file from scratch; anything else appends, which is what makes a resumed run add to the existing file instead of wiping it.
totalINT11–1000000How many items the batch has. Used for the progress bar.
modeCOMBOOne file, blocksBlocks separated by a blank line (read back by TS Batch Prompt Loader); one line per item (read back by TS Batch Source in 'Lines in text file' mode — this is what closes the loop from captions to generation); or one .txt per item named after it, the layout caption datasets expect.
output_pathSTRINGTarget file in 'one file' mode, target folder in 'per item' mode.
nameoptSTRINGName for this item's .txt, without extension. Usually the 'name' output of TS Batch Load Image, so the caption sits beside its picture.
prefix_with_nameoptBOOLEANfalseIn the one-file modes, put the item's name in front of the result — on its own line for blocks, tab-separated for one line.
imageoptIMAGEOptional. Shown on the progress bar as each item finishes — the only way to watch results arrive, since ComfyUI holds normal previews until the whole batch is done.

Outputs (1)

NameTypeDescription
textSTRINGThe same text, passed through so the chain can continue.