get extension
Grab the .png off a filename — no regex required
- extension
Basic data handling: PathGetExtension ("get extension") does exactly one thing: it pulls the file extension off a path and hands it back to you, dot included. photo.png → .png, archive.tar.gz → .gz, noext → "". That's the whole node, and it's genuinely handy when your workflow needs to know what kind of file it's about to touch.
The concrete case: you've globbed a folder of images with PathGlob or listed it with PathListDir, and you want to branch - feed PNGs into one path, JPEGs into another, or skip anything that isn't a .png before it reaches a loader. Compare the extension output against a string in a comparison node (this same pack's "StringComparison" is a natural fit) and you've got a format filter without touching a single regex. It's also useful before a save: check what extension a filename already has so you don't end up with out.png.jpg.
How it works
The implementation is a call to Python's os.path.splitext(path) and taking the second element. That means the behavior is Python's behavior, which is worth knowing on two edges:
- Only the last extension is returned.
image.tar.gzgives.gz, not.tar.gz. If you need the middle extension, that's not what this node does. - No extension → empty string. Files without a dot return
"", so your comparison branches on emptiness, not on a sentinel. - Hidden files are a small trap:
.gitignorereturns.gitignoreundersplitext's rules on some platforms because the whole name starts with a dot. Edge case, but it's the kind of thing that makes you double-take in a filter.
Inputs and outputs
- path (STRING, default
"") - the filename or full path you're inspecting. - extension (STRING) - the extension including the leading dot, or
""if there is none.
Installing it
Ships in Basic data handling, the dependency-free pack from StableLlama. Install via ComfyUI Manager (search "Basic data handling") and restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart after. No models, no extra pip packages - ComfyUI already provides the Python stdlib this node runs on.
Where it bites
Nothing exotic here, but two habits save grief. First, remember the output includes the dot - compare against .png, not png. Second, the empty-string result for extensionless files: if you're building a default extension in, test for "" explicitly rather than assuming something came back. Beyond that, it's a small, predictable utility that does what it says and stays out of the way. That's the whole point of a pack like this.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| path | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| extension | STRING | — |