Most Recent File Selector (Buff)
Grab the newest file in a folder — your own personal 'latest output' hook
- file_path
Some workflows are about what's newest, not what's random. This node scans a directory, finds the file with the most recent modification time, and returns its full path. The killer detail: it always re-runs on every queue, so the moment a new file lands in the folder, the next run picks it up automatically.
The classic setup is "run an upscaler on the latest output of my previous workflow." Point this at an output directory, filter by png, and wire the returned path into an image loader - you've built a simple watch-folder pipeline without any scripting. It's also the natural companion to the batch-file ideas in the rest of this pack: random file for variety, most-recent file for "just did this, now process it."
How it works
It walks the directory with os.scandir, compares modification times, and returns the newest matching file. file_types is a comma-separated extension filter - leave it empty to consider every file. Two behaviors make it feel smarter than a plain "find the newest file" utility.
First, IS_CHANGED returns float("NaN"), the ComfyUI idiom that forces a node to re-execute every single time the graph runs. The node has to do this, because "has a new file appeared since last time?" is a question about the disk, and ComfyUI's cache only looks at node inputs. The cost is the same as any always-dirty node: it also forces everything behind it to re-run, so it'll fight caching in long pipelines. That's the right trade for its purpose.
Second, create_init_image_if_not_found. If the folder is empty (or the directory doesn't exist), it can generate a black image at init_image_width × init_image_height, saved as png or jpg into that directory, and return its path. So a fresh workflow run doesn't choke on an empty folder - it gets a black starter image, which is exactly the "initialization image" workflow the README describes. Flip that off and an empty folder returns an empty string instead.
The inputs
directory_path- the folder to scan; defaults to ComfyUI's input directory.file_types- optionalpng,jpgstyle filter; blank means everything.create_init_image_if_not_found- the black-image fallback toggle.init_image_width/init_image_height/init_image_format- only relevant when that toggle is on.
One output, file_path, a plain string. It logs what it found to the console, which doubles as a debugging breadcrumb.
Install
It's in BuffMcBigHuge's QoL pack - ComfyUI Manager (search "ComfyUI-Buff-Nodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/BuffMcBigHuge/ComfyUI-Buff-Nodes
Restart ComfyUI. No extra dependencies or downloads.
Gotchas
Nothing deep. Note that "most recent" is by modification time, so touching a file (even without editing) promotes it. The black-image fallback writes directly into directory_path - if that's your output folder, you're polluting it with black_image_<timestamp>.png files on every empty run; toggle it off once you have real output. And remember the always-rerun behavior means this node re-executes on every queue regardless of inputs - intended, but if you ever see a slow workflow and wonder why, this is a likely culprit.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| directory_path | STRING | /tmp/ComfyUI/input | Path to search for files. Can be absolute or relative path. |
| file_types | STRING | Optional comma-separated list of file extensions to filter by (e.g., 'png,jpg'). Leave empty for all files. | |
| create_init_image_if_not_found | BOOLEAN | false | When True, creates a black image if no matching file is found. |
| init_image_width | INT | 51264–4096 | Width of the black image to create if no file is found. |
| init_image_height | INT | 51264–4096 | Height of the black image to create if no file is found. |
| init_image_format | COMBO | png | Format to save the black image in if no file is found. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| file_path | STRING | — |