Nodes/ComfyUI_demucus/Path Basename
ComfyUI Node

Path Basename

Pulling the filename out of a full path

By kale4eat·Created 2 years ago·Updated 2 years ago· 0
Path Basename
    • basename
    path
    without_extfalse

    A checkpoint loader hands you a full path like models/checkpoints/dreamshaper_8.safetensors. What you actually want, half the time, is just dreamshaper_8.safetensors - to show in a title, to stamp into a filename, to check what model a workflow is built around. That's exactly what Path Basename does: it strips everything except the final filename component.

    It's the file-half of the directory/file split, and it's probably the most-used node in this pack. ComfyUI deals in path strings everywhere and gives you almost no string math natively, so when you need the filename separate from the folder, this is the no-fuss way to get it.

    How it works

    Under the hood it calls os.path.basename(path). If you flip the without_ext toggle on, it takes that result one step further and slices off the extension too - so dreamshaper_8.safetensors becomes dreamshaper_8. The extension-stripping is done with os.path.splitext, the same mechanism as the pack's Path Splitext node.

    One behavior to know: for a path that ends in a separator (models/checkpoints/), basename returns an empty string. So if you're feeding this from a folder path and getting nothing back, that's why - it expects a path that ends in a filename.

    Inputs and outputs

    Only two things you'll ever set:

    • path (STRING) - the full path to pull the filename from.
    • without_ext (BOOLEAN, default off) - leave off and you get image.png; flip it on and you get image.

    Output is basename (STRING), ready to wire into any string input - a filename-prefix builder, a text display, or further string manipulation from this pack or others.

    Installing it

    The pack installs clean with no dependencies at all - no pip, no models, pure standard library. ComfyUI Manager users: search "path-util" and install. Everyone else:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kale4eat/ComfyUI-path-util
    

    Then restart ComfyUI. There's no requirements.txt to worry about, which is a nice change of pace in an ecosystem where half the battle is dependency conflicts.

    Common issues

    The most common stumble is the without_ext toggle doing the "wrong" thing: with it on, a file like photo.v2.png becomes photo.v2, stripping only the last extension - Python's splitext only ever splits at the final dot. That's almost always what you want, but if you expect photo you'll be surprised.

    Also remember this node doesn't check that the file exists or that the path is even valid - it's purely textual. Feed it garbage, it happily strips garbage. If you need to know whether the file is real before you do anything with its name, chain it after Path Exists, not instead of it.

    Categorypath-util

    Inputs (2)

    NameTypeDefaultDescription
    pathSTRING
    without_extBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    basenameSTRING