Ends with
The ComfyUI node that sniffs file extensions
- result
Ask yourself: when was the last time you needed to know if a string contained another string vs. what it ended with? For text, contains covers most cases. But the moment you start working with filenames - and in ComfyUI, you always end up working with filenames - "what does this string end with?" is the question that actually matters. "photo.png" vs "photo.webp" both contain the same things; only an ends-with test tells them apart.
This node comes from ComfyUI-BooleanExpression, Marco Zanella's dependency-free logic pack. It answers one question: does the first string finish with the second? Yes → it outputs true, no → false, and that boolean becomes a fork in your graph when you feed it into the pack's Conditional Branch.
How it works
The mechanism is a thin Python call: haystack.endswith(needle), with both strings lowercased first when case-insensitivity is on. That's it - no hidden state, no dependencies, no model to download. One input is the text, the other is the suffix you're checking for, and the output is a single result boolean.
Three required inputs:
- haystack - "The string." The text you're testing.
- needle - "The string to search." The suffix it must end with.
- case_insensitive - defaults to True.
The default matters here more than you'd think. File extensions come in every case: .PNG, .WebP, .jpg. Because this node folds case by default, "output.PNG" endswith ".png" returns true without you having to match the case yourself. Flip it off only if you genuinely care about capitalization at the tail of the string.
The extension-sniffing pattern
The use case the display name doesn't advertise: checking what kind of file you're dealing with. Load a filename from a loader node, run it through EndsWith, and branch:
filenameends with.png→ straight to a PNG-specific post-processing path.- ends with
.webp→ convert first, or skip the alpha handling. - prompt ends with
", highly detailed"→ maybe you don't want the second upscale pass after all.
The output wires into the same places every boolean in this pack does - Conditional Branch, the And/Or/Xor/Not group, or any BOOLEAN input. Pair it with the pack's Does not end with if you'd rather express the negative, or skip the extra node and just put a Not after it.
Install
Fastest via ComfyUI Manager: search ComfyUI-BooleanExpression, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/marco-zanella/ComfyUI-BooleanExpression.git
Then restart ComfyUI and look under Boolean Expressions → String Comparisons. The pack is pure Python with an empty requirements.txt - no pip step, no models, nothing heavy. It's on the Comfy Registry, so Manager resolves it by title without you hunting for a repo URL.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| haystack | STRING | The string. | |
| needle | STRING | The string to search. | |
| case_insensitive | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | BOOLEAN | — |