Nodes/CMK Flow/CMK Filename Base
ComfyUI Node

CMK Filename Base

Turn 'C:\\...\\portrait (2).png' into Something You Can Use

By CMKFlow·Created 3 months ago·Updated a day ago· 6
CMK Filename Base
    • basename
    ◄filename—►

    This is a one-input, one-output string node, and it does exactly one thing: given a path, it hands back the name of the file without the folder and without the extension. Boring. Also the thing you need the moment you want a batch of generated images named after their source.

    What it does

    Feed it a path - filename is a STRING with forceInput, meaning it's wired, not typed - and it runs three steps:

    1. os.path.basename strips the directory.
    2. os.path.splitext drops the extension.
    3. A regex strips a trailing Windows/duplicate suffix: portrait (2) becomes portrait.

    Then it returns that as basename. Nothing else, no second output, no mode switch.

    Step 3 is the one worth noticing, because it's a specific opinion: the "(2)" convention from file managers and download folders is noise, and this node assumes you'd rather have portrait than portrait (2) as a filename stem. If you're deliberately versioning with those suffixes, this node will eat them.

    Why you'd reach for it

    Naming. It's the classic batch problem - you load a folder of reference photos, generate one output per photo, and want the outputs to be traceable back to their sources rather than numbered ComfyUI_00017_.png and lost forever.

    CMK's own CMK Filename Base shows up in the pack's save paths for exactly that: taking the source image's name through to a filename prefix so a hundred outputs sort into something legible.

    One thing to be clear about while you're building that habit: filenames are cosmetic. They are not where your reproducibility lives. That's in the metadata ComfyUI embeds into the PNG when SaveImage writes it - the workflow and prompt chunks - and that's lost the instant anything re-encodes the file. Name your files however you like; keep the PNG as the master.

    Where the naming intuition breaks

    If you feed it something that SaveImage produced, you may expect ComfyUI_00001_ to become ComfyUI. It won't - the node strips a trailing (2)-style suffix, not ComfyUI's _00001_ counter. Both look like "the same name with a number on it" and they're not the same convention.

    Second, and more likely to bite: nodes that don't read files as paths. CMK's own image loaders hand out a image_file string that's a ComfyUI reference - an annotated filepath relative to input/, or one of the pack's packaged references - not an absolute path. os.path.basename handles that fine, since the last path segment is still the filename. Just don't build further string surgery on the assumption that it's absolute.

    Third: the extension is gone for good. If you need to reconstruct the path later, you can't, because you no longer know whether it was .png or .jpg.

    Install

    Manager: search CMK Flow, install the CMKFlow entry, restart. Manually, from your ComfyUI root:

    git clone https://github.com/CMKFlow/cmk_nodes.git custom_nodes/cmk_nodes
    python3 custom_nodes/cmk_nodes/scripts/install_cmk_requirements.py
    

    That helper is not optional for a git clone - a manual clone never runs pip for you, and the pack's dependencies (ultralytics, onnxruntime, insightface, segment-anything, imageio-ffmpeg, nudenet, opencv-python) are heavy and load-bearing elsewhere in the pack. This node itself needs nothing but Python's standard library, so it's a good smoke test: if CMK Filename Base appears in the node list, the pack loaded. If it appears but its neighbours error, your problem is a dependency or a model file, not the install.

    Model weights aren't involved here at all, but the resource check is still the right next step for the pack:

    python3 custom_nodes/cmk_nodes/scripts/check_cmk_resources.py --models-root "/path/to/ComfyUI-Shared"
    

    The honest verdict

    Wire it into a save prefix and forget it exists. It's the sort of utility that's invisible when present and quietly annoying when missing - which is, more or less, the definition of ComfyUI's plumbing layer. Most workflows are 70% this stuff.

    CategoryCMK/Toolbox/I-O

    Inputs (1)

    NameTypeDefaultDescription
    filenameSTRING—

    Outputs (1)

    NameTypeDescription
    basenameSTRING—