ComfyUI Node

Prefix [m9]

Filenames You Can Still Sort Through Next Week

By MarcusNyne·Created 3 years ago·Updated 3 days ago· 1
Prefix [m9]
    • prefix
    name
    theme
    scene
    frame

    Save twenty variations on a theme and you get ComfyUI_00001_.png through ComfyUI_00020_.png, which tells you nothing about any of them a week later. Prefix [m9] is the small node that fixes that: four text fields - name, theme, scene, frame - joined with underscores and handed to a SaveImage node's filename_prefix.

    That's it. It's a string builder. But it's the difference between an output folder you can search and a folder you scroll.

    How it works

    Each of the four values gets trimmed and sanitised, then the non-empty ones are joined in order with _ between them. Empty fields are skipped along with their separator, so a lone name comes out with no underscore at all, and name plus scene gives you render_night-market. Nothing fills them in but you.

    Sanitising means characters Windows won't accept in a filename - < > : " / \ | ? * - become underscores, as do invisible control characters. Trailing dots and spaces get stripped, because Windows silently drops them and then the name on disk doesn't match the name in your widget. If all four fields are empty the output is literally ComfyUI, which is the same default SaveImage uses on its own, so an unconfigured node still produces valid filenames instead of a mess of underscores.

    The fields and the output

    name, theme, scene, frame - four single-line string widgets, joined in that order. They're all technically required widgets rather than optional inputs, but an empty field is simply skipped, so in practice you fill in however many you need. Any of them can be right-click → Convert to input and driven by another node; frame fed from a counter or an index is the obvious one if you're naming a sequence.

    One output: prefix (STRING). Convert the filename_prefix widget on your SaveImage node to an input and wire this into it. Two nodes, and every save in the workflow is now self-describing.

    Installing it

    ComfyUI Manager → search m9-prompts-comfyui → install. Or the manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MarcusNyne/m9-prompts-comfyui
    

    Restart afterwards. No dependencies to install and no model files - the pack is pure Python and leans only on torch/numpy/Pillow, which ComfyUI already ships. It's the ComfyUI port of the same author's older A1111/Forge prompt-scrambling extension, and Prefix [m9] is the pack's plumbing node: it appears in the example workflows that ship with the repo, naming the outputs of the ScramblePrompts and StepReplace examples.

    The one thing to know before you wire it

    The sanitiser is not smart about ComfyUI's own filename templating, and it will quietly ruin it. %date:yyyy-MM-dd% contains a colon, so it comes out as %date_yyyy-MM-dd%; portraits/run_a contains a slash, so your subfolder becomes portraits_run_a. Those tokens and subfolders belong in the SaveImage field directly, next to the prefix - not in this node's fields. The README is upfront about this, and the code does exactly what it says, so it's not a bug hunt you need to do twice.

    Also worth internalising: filenames are cosmetic. ComfyUI embeds the prompt and workflow inside every PNG, and that is where your reproducibility lives. Prefix [m9] makes a folder browsable; it doesn't make anything reproducible. If the real goal is provenance, the metadata is already handling it.

    Troubleshooting

    If every image still lands as ComfyUI_000xx_.png, check the wiring first - the filename_prefix widget has to be converted to an input before the socket exists, and it's easy to leave the node's prefix output dangling while SaveImage keeps using its own default.

    If your prefix looks wrong in an odd way, look for characters that got substituted rather than wondering whether the node ran. Whatever is between the underscores came from a field, and whatever is now an underscore was illegal or invisible. Reversed field order is the other one to check: it's always name, theme, scene, frame - not the order you filled them in.

    Categorytext

    Inputs (4)

    NameTypeDefaultDescription
    nameSTRING
    themeSTRING
    sceneSTRING
    frameSTRING

    Outputs (1)

    NameTypeDescription
    prefixSTRING