ComfyUI Node

splitext

Strip the extension off a filename, properly

By StableLlama·Created about a year ago·Updated 4 days ago· 48
splitext
    • path without ext
    • extension
    path

    "Get me the filename without its extension" sounds trivial until you try to do it with string nodes and realize .jpg hiding inside a longer name is a classic trap. This node is os.path.splitext() wearing a ComfyUI costume: give it character_render_v2.png and it returns character_render_v2 and .png as two strings. It's the node you reach for when you want to build an output filename from an input filename without typing the stem by hand.

    It's also the natural partner to the pack's split node. split tears the directory off the front; splitext tears the extension off the back. Run a path through both and you've got the three parts every filename generator needs - folder, stem, extension - ready to be recombined any way you like.

    How it works

    Straight call to os.path.splitext(), which means the extension includes the dot (.png, not png). Two Python behaviors to know, both of which will bite you exactly once:

    • Only the last suffix counts. archive.tar.gz splits into archive.tar and .gz. If you're writing code to swap .tar.gz wholesale, this node won't do it in one pass.
    • A leading dot is not an extension. .gitignore splits into ('.gitignore', '') - nothing after the dot gets treated as a suffix, because there's nothing before it.

    Neither is a bug, but both explain "why is my extension empty" moments in real workflows.

    Inputs and outputs

    One input, path (default empty string). Two outputs:

    • path without ext - everything before the final dot.
    • extension - the dot plus suffix, or '' if there is none.

    Wire path without ext into PathSetExtension to replace the extension in a controlled way, or into PathJoin to rebuild a path in a different directory.

    Installing it

    It's one of ~200 nodes in the Basic data handling pack by StableLlama. Install the pack once:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart, or install via ComfyUI Manager by searching "Basic data handling". The pack declares zero dependencies and pulls no models, so there's no pip wrangling and nothing to break your environment.

    Gotchas

    • Extension includes the dot. If you're feeding the result into something that expects a bare suffix, strip it first or use PathSetExtension's built-in dot handling instead.
    • It's string-only: no filesystem access, no existence check. The path can be pure fiction and the node will still happily split it.
    • If the path has no extension at all, extension comes back empty - that's the success case for "there's nothing to split," not an error.
    CategoryBasic/Path

    Inputs (1)

    NameTypeDefaultDescription
    pathSTRING

    Outputs (2)

    NameTypeDescription
    path without extSTRING
    extensionSTRING