removesuffix
Removesuffix — peel the extension off a filename without the guesswork
- STRING
The most common thing at the end of a string is a file extension, and the most common reason you care is that you don't want it. removesuffix deletes a suffix from the end of a string - but only if it's actually there. No match means no change, no error, no partial strip. It's the safest possible way to turn photo.png into photo.
Reach for it when you're cleaning up filenames, stripping units off measured values ("128px" → "128"), or pulling a file extension off before you build a new filename with a different one. Because it's a no-op when the suffix isn't present, it's safe to run across a whole batch of strings without checking each one first.
How it works
Python's str.removesuffix(suffix) - exact, literal, and end-anchored:
"photo.png".removesuffix(".png")→"photo""photo.jpeg".removesuffix(".png")→"photo.jpeg"(no match, unchanged)"photo.PNG".removesuffix(".png")→"photo.PNG"(case-sensitive, no match)"my.png.png".removesuffix(".png")→"my.png"(removes one occurrence, the trailing one)
It looks at the end of the string only, and removes exactly one occurrence. It won't touch a .png in the middle of the name.
Inputs and outputs
Two required inputs:
string- the text to clean.suffix- the exact string to remove from the end.
Output is one STRING - the cleaned copy.
Installing it
Part of the Basic data handling pack by StableLlama. ComfyUI Manager, search "Basic data handling", install, restart. Manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Pure Python, zero dependencies, no downloads - installs clean and stays out of the way. Under Basic/STRING in the menu.
Common issues
Case-sensitivity bites on real-world files constantly: removesuffix(".PNG") won't strip a .png and vice versa, so if your filenames come from mixed sources, lowercase the whole name first with this pack's lower node, then strip. And remember it removes exactly one suffix occurrence - "archive.tar.gz".removesuffix(".gz") gives "archive.tar", which is correct but means you can't get from .tar.gz to archive in one call; chain it if you need two levels. Also, this strips a literal suffix, so there's no pattern matching - if your "extension" varies, the pack's split (to data list) or rfind approach is the more flexible route.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| suffix | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |