MD: Filename Token Replacer
Name your files like a project folder, not a timestamp
- result_string
- preview
Your output folder is a mess of ComfyUI_00042_.png, and someday you'll have 4,000 files and no idea which one was the good Flux run at 30 steps. FilenameTokenReplacer is a template engine for filenames - you write a pattern with {tokens} in it, feed it values, and it hands back a clean, organized string you can drop straight into a save node.
It's the same idea as the filename_prefix strftime codes a lot of save nodes accept, but more explicit and more bendable: instead of remembering %Y-%m-%d you just write {date}, and instead of being stuck with date tokens you get project, mode, steps, seed, genre, and two custom slots.
The template
The template input is the whole node. Default is {project}/{date} - {steps}S - {mode}, which resolves to something like MyProject/2026-08-16 - 30S - Image. Note the / - the node will happily build a folder path, so {project}/Session_{date}_{mode} becomes a per-project, per-day subdirectory. That's the kind of organization that makes a thousand-output folder actually navigable.
Tokens you can use:
{project},{mode},{genre}- plain text inputs.genregets auto-cleaned (illegal filename characters stripped).{steps},{seed}- numbers.{date}and{time}- formatted viadate_format(default%Y-%m-%d) andtime_format(default%H-%M-%S). Same strftime codes as everywhere else in Python-land.{custom1},{custom2}- two free slots for whatever you're tracking.
Outputs
Two wires: result_string (the resolved, sanitized path - this is the one that goes into your save node's prefix) and preview (the same thing, included so you can pipe it into a text display and see what the filename will be before you commit to it). Wire the preview into a Show Text node and you can sanity-check the pattern without generating anything.
A nice touch: it connects cleanly to this pack's FilenameCounterNode, so {project}/{counter} - {date} gives you both a project folder and a never-repeating sequence number.
Installing it
It ships in MD Nodes (MDMAchine/ComfyUI_MD_Nodes) alongside the other filename utilities. ComfyUI Manager → search MD_Nodes → Install, restart. Manual route:
cd path/to/ComfyUI/custom_nodes
git clone https://github.com/MDMAchine/ComfyUI_MD_Nodes.git
cd ComfyUI_MD_Nodes
pip install -r requirements.txt
Restart ComfyUI. Standard pack context: Python 3.10+, GPL v3, pure Python.
Common issues
The usual miss is expecting a token to work before it has an input - {steps} renders as empty unless you've wired the steps value in, and {genre} needs a string even if it's just "". Also, the sanitizer runs on the result, so a genre with spaces or slashes gets scrubbed for filename safety; if your output looks shortened, that's the cleaner working as advertised, not a bug. If you're chaining this into a save node, remember you're producing a prefix - the save node still appends its own numbering or timestamp, which is exactly what you want to avoid collisions.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| template | STRING | {project}/{date} - {steps}S - {mode} | TEMPLATE STRING • Purpose: Text pattern with tokens to be replaced. • Tokens: {date}, {project}, {mode}, {steps}, {seed}, {genre}. ⭐ Example: '{project}/Session_{date}_{mode}' |
| projectopt | STRING | MyProject | Token replacement for {project}. |
| modeopt | STRING | Image | Token replacement for {mode}. |
| stepsopt | INT | 0 | Token replacement for {steps}. |
| seedopt | INT | 00–9007199254740991 | Token replacement for {seed}. |
| genreopt | STRING | Token replacement for {genre} (auto-cleaned). | |
| custom1opt | STRING | Token replacement for {custom1}. | |
| custom2opt | STRING | Token replacement for {custom2}. | |
| date_formatopt | STRING | %Y-%m-%d | Format for {date} token (Python strftime). |
| time_formatopt | STRING | %H-%M-%S | Format for {time} token (Python strftime). |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| result_string | STRING | — |
| preview | STRING | — |