Filename List π¦βπ₯
Generate your batch filenames before you've saved anything
- filenames
Batching in ComfyUI usually hits the same wall: you render 10 images, and if your save node uses a fixed name, nine of them get overwritten. The classic fix is to include a batch index in the filename. This node is that fix, generalized - it generates the list of filenames before you have any output, so you can pair each batch item with its own name.
How it works
It's dead simple string math. Given a prefix, a digit count, a starting number, and a count, it produces zero-padded filenames like AG_0000.png, AG_0001.png, and so on:
num_files = 10, prefix = "AG", num_digit = 4, num_start = 0
β ["AG_0000.png", "AG_0001.png", ..., "AG_0009.png"]
The four required inputs map directly to that: num_files (how many), filename_prefix (default "AG"), num_digit (zero-padding width, default 4), num_start (where to start counting, default 0).
Then there's optional_idx, the one that changes behavior. Leave it at -1 (default) and you get the full list. Set it to any other value and you get a single string for that one index - AG_0003.png - which is exactly what you want when you're inside an iteration loop (like the pack's Iterate Items) and each pass needs one specific filename.
The output filenames is an * port, so it can carry either the list or the single string depending on how you used optional_idx.
Where it fits
The natural pairing is with the pack's iterate nodes: Iterate Items walks a list, Filename List (with optional_idx wired to the loop's index) hands each pass its own name, and a save-to-path node uses it. No more "how do I not overwrite batch outputs" - you generate the naming scheme up front.
The traps
- The extension is hardcoded to
.png. There's no jpg/jpeg option. If you want PNG output this is perfect; if you're saving webp or jpg, this node's names won't match. num_startcan be non-zero - useful for resuming a run at index 20 without renumbering everything.- It's just string generation. Nothing gets written or read; the node has no idea whether a file exists. That's the point (it runs before saves), but don't expect it to check for collisions.
Install
ComfyUI Manager β search ComfyUI-ArchiGraph, or:
cd ComfyUI/custom_nodes
git clone https://github.com/vincentfs/ComfyUI-ArchiGraph
Restart and run the pack's install script once. This node is pure Python - no OpenCV involved.
Verdict
A tiny utility that only earns its keep inside a batch loop, but inside one it's the difference between "10 files, 9 overwritten" and "10 numbered files." Cheap, predictable, no surprises - the good kind of boring.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| num_files | INT | 10 | Number of filenames to generate. |
| filename_prefix | STRING | AG | Prefix for the filenames. |
| num_digit | INT | 4 | Number of digits in the filename. |
| num_start | INT | 0 | Starting number for the filename. |
| optional_idxopt | INT | -1 | If specified (not -1), generate only the filename for this index. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| filenames | * | β |