Nodes/MD Nodes/MD: Filename Token Replacer
ComfyUI Node

MD: Filename Token Replacer

Name your files like a project folder, not a timestamp

By MDMAchine·Created about a year ago·Updated 3 months ago· 15
MD: Filename Token Replacer
    • result_string
    • preview
    template{project}/{date} - {steps}S - {mode}
    projectMyProject
    modeImage
    steps0
    seed0
    genre
    custom1
    custom2
    date_format%Y-%m-%d
    time_format%H-%M-%S

    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. genre gets auto-cleaned (illegal filename characters stripped).
    • {steps}, {seed} - numbers.
    • {date} and {time} - formatted via date_format (default %Y-%m-%d) and time_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.

    CategoryMD_Nodes/Utility

    Inputs (10)

    NameTypeDefaultDescription
    templateSTRING{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}'
    projectoptSTRINGMyProjectToken replacement for {project}.
    modeoptSTRINGImageToken replacement for {mode}.
    stepsoptINT0Token replacement for {steps}.
    seedoptINT00–9007199254740991Token replacement for {seed}.
    genreoptSTRINGToken replacement for {genre} (auto-cleaned).
    custom1optSTRINGToken replacement for {custom1}.
    custom2optSTRINGToken replacement for {custom2}.
    date_formatoptSTRING%Y-%m-%dFormat for {date} token (Python strftime).
    time_formatoptSTRING%H-%M-%SFormat for {time} token (Python strftime).

    Outputs (2)

    NameTypeDescription
    result_stringSTRING
    previewSTRING