Extract & Trim Filename (No Extension)
From Full Path to Clean Filename in One Tiny Node
- processed_filename
The pitch is right there in the name. Extract & Trim Filename (No Extension) takes a full file path, like C:/Images/photo_upscaled_v1.png, and hands you back just the meaningful part of the name - photo - with the directory and extension stripped. It does exactly one thing, it does it in pure Python with zero dependencies, and for about a tenth of your workflows it's the difference between an output folder full of ComfyUI_00001_ and one that actually tells you what's in it.
Why would you reach for it? ComfyUI's built-in SaveImage takes a static filename_prefix. Type portrait and every save is portrait_00001_, forever. When you're processing an input image and want the output named after that image - upscale an image, save the upscaled version with the same base name; batch through a folder, keep the names recognizable - you need a string computed from the input, not typed by hand. That's this node. Feed it the path string, wire processed_filename into any string input, and your saves start naming themselves.
Here's the mechanism, which is genuinely all of it: it runs os.path.basename() to drop the directory, os.path.splitext() to drop the extension, then searches for your trim_marker. If the marker exists in the name, everything from the marker onward gets chopped. _upscaled in photo_upscaled_v1 → photo. If the marker isn't found, no harm done - you just get the clean name with the extension removed.
The inputs you'll actually set are both plain strings:
file_path- any path string. The default is just the author's example; you'll usually wire this from a node that outputs a path (the pack's siblingLoadImageWithFilenamereturnsimage_pathprecisely for this).trim_marker- optional. Whatever substring marks the point where the useful name ends:_upscaled,-RAW,_final, whatever your naming convention uses. Leave it empty if you only want the extension gone.
The single output, processed_filename (STRING), plugs into SaveImage's filename_prefix, text nodes, or anything that eats a string - including building captions for a LoRA training set where the filename doubles as the label.
Install is about as painless as custom nodes get. Via ComfyUI Manager, search "Filename Tools"; or:
cd ComfyUI/custom_nodes
git clone https://github.com/skycoder182/comfyui-filename-tools
then restart ComfyUI. The README's requirements file literally reads "No external dependencies" and the pyproject confirms it - there are no model downloads, no pip packages, nothing heavy. It's two small .py files.
Now the traps, because the README's example flatters this node. It does not strip the trailing (2) from ImageName (2) - that's the other node in this pack. The README table showing photo_upscaled (2).png → photo is describing the sibling LoadImageWithFilename, which has its own dedup regex. Here you get no such help. Also: the marker match is case-sensitive and takes the first occurrence, so _Final won't match _final, and a_b_c trimmed on _ gives you just a. And one platform gotcha worth knowing: on a Linux box, a pasted Windows path with backslashes won't be split, because os.path.basename on Linux only recognizes /. Forward slashes work everywhere; backslashes only on Windows.
Honest verdict: this is not a node you build a workflow around, and you wouldn't install this pack for it. But if the pack is already there, or you batch-save and are tired of renaming files by hand, it's a one-wire fix for a surprisingly common annoyance. The name is the whole product, and the product works.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| file_path | STRING | C:/Images/Image_xyz_123.png | — |
| trim_marker | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| processed_filename | STRING | — |