ComfyUI Node

set extension

Swap a file extension without touching the rest of the path

By StableLlama·Created about a year ago·Updated 4 days ago· 48
set extension
    • path
    path
    extension.txt

    The boring nodes are the ones you end up using every day, and "set extension" is about as boring as a node gets. You give it a path and a new extension, and it returns the same path with a different suffix. That's it. No file I/O, no globbing, nothing clever. Which is precisely why it's useful: in any workflow that builds output filenames from other filenames, extension surgery is a step you keep needing.

    The typical move: you load an input like /input/img_0001.png, run your processing, and want to save a result next to it as .jpg or .txt - same stem, different suffix. Instead of retyping the whole path, you chain a couple of Path nodes and let the graph rebuild it. It's the kind of plumbing that makes a workflow reusable instead of a one-off you hand-edit every run.

    How it works

    Mechanically it's os.path.splitext() on the input to peel off whatever extension is there, then string concatenation of the root with your new extension. Two small conveniences are baked in: if your extension is missing the leading dot (you type png instead of .png), it adds the dot for you, and the default is .txt so the node is already sensible if you wire a filename straight into a "save STRING" node.

    One thing worth knowing: it replaces whatever is there, it doesn't append. render_v3.final.png.jpg gives render_v3.final.jpg, not render_v3.final.png.jpg. And if the path has no extension at all, the new one just gets tacked onto the end.

    Inputs and output

    • path - the path to modify.
    • extension - new extension; dot optional, default .txt.

    One output, path, holding the rebuilt string. Wire it into any node that takes a path - this pack's own PathSaveImageRGB, PathSaveStringFile, or the loaders.

    Installing it

    It's part of the Basic data handling pack by StableLlama. Install the pack once and every Path node arrives together:

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

    Restart, or just use ComfyUI Manager and search "Basic data handling". The pack has no dependencies and no model files - pure Python stdlib wrapped as nodes - so there's nothing to go wrong at install time.

    Gotchas

    • It's a string transformation, not a rename. Nothing on disk changes, and it won't tell you if the path even exists.
    • Multi-dot names behave like splitext does in Python: only the last suffix is replaced, and a leading-dot file like .gitignore splits as ('.gitignore', ''), so the "extension" lands on an already-hidden file's name. Edge case, but it's the one that bites people doing config-style filenames.
    CategoryBasic/Path

    Inputs (2)

    NameTypeDefaultDescription
    pathSTRING
    extensionSTRING.txt

    Outputs (1)

    NameTypeDescription
    pathSTRING