Nodes/ComfyUI_demucus/Path Splitext
ComfyUI Node

Path Splitext

Separating a filename from its extension

By kale4eat·Created 2 years ago·Updated 2 years ago· 0
Path Splitext
    • root
    • ext
    path

    Sometimes you need myimage.png as two pieces: the name myimage and the extension .png. Maybe you're building an output filename with a different extension, or checking whether a file is actually a .safetensors, or stamping a version suffix onto a base name. Path Splitext is the two-output node that does that split, and it's the quiet workhorse of this pack.

    It's the node that Path Basename's without_ext toggle uses under the hood - if you've used that, you already know how this behaves. It just gives you both halves instead of only one.

    How it works

    One call to os.path.splitext(path), which returns a tuple of two strings: everything before the final dot, and the dot-plus-extension. A few behaviors to know:

    • The extension includes the dot: image.png splits into image and .png. People forget this and build filenames that end up with double dots.
    • Only the last dot splits. photo.v2.png becomes photo.v2 and .png. If you expected photo, this isn't the node for that.
    • No extension at all → ("filename", "") - an empty extension string, no dot.
    • Dotfiles like .gitignore split into (".gitignore", "") - the leading dot is not treated as an extension separator.

    Inputs and outputs

    • path (STRING, default empty) - the path to split.
    • root (STRING) - everything before the extension.
    • ext (STRING) - the dot plus extension.

    Both outputs wire into any string input. The classic composition: take root, append a new extension with a string-concat node (or Path Join if you've patched it), and you've got a filename with a swapped format. Or feed ext into a boolean comparison to branch on file type.

    Installing it

    The pack is dependency-free - pure standard library, no requirements.txt, no pip step, no model downloads. About as safe an install as custom nodes get.

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

    Restart ComfyUI, or use Manager and search "path-util."

    Common issues

    Most of the confusion is the dot. ext comes out as .png, not png, so if you're concatenating an extension onto a name, don't add another dot or you'll get photo..png. And the last-dot-only rule bites anyone who works with versioned filenames - final.v2.png gives final.v2, which is usually what you want, but worth knowing before it surprises you.

    Also note the split is purely textual and operates on the last component, not the whole path - feed it /path/to/image.png and you get /path/to/image and .png, which is exactly right for rebuilding paths. Combined with Path Dirname and Path Basename you can take a path apart piece by piece and put it back together differently, which is most of what this entire pack is for.

    Categorypath-util

    Inputs (1)

    NameTypeDefaultDescription
    pathSTRING

    Outputs (2)

    NameTypeDescription
    rootSTRING
    extSTRING