๐บ Extract Filename from Path
Filename juggling for batch workflows, minus the regex
- name
- name_with_extension
When you're automating image processing in ComfyUI, the filename is data. Maybe you're using it as a prompt, a metadata tag, or just organizing outputs by source file. Stock ComfyUI gives you file paths all over the place - from loaders, from ๐บ Load Image By Index's filepath output, from custom save nodes - but it rarely gives you a clean basename. Nilor Extract Filename from Path is a one-trick node that does exactly one job: take a filepath, give you the filename, with and without the extension.
How it works
It's literally two lines of pathlib under the hood, which is the right amount of machinery. You feed it a filepath string; it raises a clear error if the string is empty; otherwise it returns:
name- the stem, i.e. the filename without the extension (my_renderfrom/outputs/my_render.png).name_with_extension- the full basename (my_render.png).
Because it uses pathlib.Path, it doesn't care whether your path uses forward slashes, Windows backslashes, or a mix - it strips the directories and gives you the last component. That's genuinely useful in this pack's world, which normalizes OS-specific path formatting between workers.
Where it fits
The natural partner is ๐บ Load Image By Index, which outputs both filename and filepath. Wire the filepath here, and you can pipe the clean name into a prompt, a caption node, or a save filename so your outputs carry the source image's identity. It's also handy after any node that returns absolute paths - you get a tidy string for the UI instead of a monster path, and you can feed the result into string math or text concatenation nodes.
The one thing to watch: this node does not verify the path exists. It only parses the string. If you need existence checks, ๐บ Count Images In Directory or ๐บ Load Image By Index will surface missing directories for you instead.
Install
Same as the rest of the pack - ComfyUI Manager, search "Nilor Nodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/nilor-corp/nilor-nodes
cd nilor-nodes && pip install -r requirements.txt
Restart, then find it under Nilor Nodes ๐บ โ Utilities. No extra dependencies for this one beyond what the pack already loads.
Honest take
This is the kind of node you'd normally just hand-roll, and if you're comfortable with Python it's trivial. What it buys you is a saved search: instead of remembering pathlib semantics mid-graph, or rebuilding the same string slicing in a text node, you drop this in and move on. The one genuine quirk is that it won't strip a trailing slash in a directory path - Path("/data/images/") returns an empty stem because there's no filename component. It's a pathlib.Path behavior, not a bug, but it means "extract the folder name from a directory path" is not this node's job. For everything else, it's the boring, reliable utility you forget is there until you need it.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| filepath | STRING | โ |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| name | STRING | โ |
| name_with_extension | STRING | โ |