Get Latest Image From Folder
Feed the Last Render Back Into the Loop
- fallback_image
- image
- frame_count
- found
- filename
The most underrated trick in iterative generation is the feedback loop: render a frame, then use that frame as the input for the next render. It's how frame-by-frame video pipelines, "next image in a sequence" workflows, and auto-queue render farms all work. The missing piece is usually the plumbing - how does the next run get the frame the last run produced? Get Latest Image From Folder is that plumbing: it reads the most recently written image from a folder, every run, on purpose.
The design is aimed straight at a specific pattern: wire the output folder of your Save Image node back into this node, and each queue run starts from wherever the previous run ended. Combined with auto-queue, that's a loop that walks forward through a sequence without anyone clicking anything.
How it works
Point folder_path at a directory (it's created if missing). Each execution:
- Scans for files matching
extensions(defaultpng,jpg,jpeg,webp,tiff,bmp), optionally filtered to names containingfilename_filter(e.g."megawarp_"to only loop over your real frames and skip stray saves). - Picks the newest by
sort_by:mtime(default, newest modified file) orname(highest natural-sorted filename). - Loads it and returns the image.
Outputs: image (the loaded frame), frame_count (total matching files - designed to be used as the next frame index), found (true if a real image loaded, false if a fallback), and filename (basename of what loaded). That frame_count output is the quietly clever part: count the files, use the count as the next index, and your workflow numbers frames automatically as the folder grows.
The node always re-runs (it's IS_CHANGED-dirty), which is essential - if it cached like a normal node it would only ever load the first file. That's also the tradeoff to remember: this node defeats caching on its branch, so keep it out of graphs where the loop doesn't need it.
Empty-folder handling is the other thing to set up. fallback_mode has three settings: passthrough (return the fallback_image input), black (a 512×512 black frame), or error (raise). For a loop that must start from scratch, passthrough with a start frame is the graceful option; for a workflow where an empty folder is a bug, error surfaces it loudly.
Install
Search "Trent Nodes" in ComfyUI Manager, or:
cd ComfyUI/custom_nodes
git clone https://github.com/TrentHunter82/TrentNodes.git
cd TrentNodes
pip install -r requirements.txt
Pure file I/O plus image decode - no models. Restart ComfyUI after installing. (The author has flagged Manager install flakiness on this pack from an early repo rename; manual clone always works.)
Common issues
- It keeps returning the same image. If your Save Image writes to a different folder than the one you pointed at, the newest file never changes. Confirm the paths match.
- It loops over the wrong files. A preview node or thumbnailer writing into the same folder pollutes the scan - that's what
filename_filteris for. - First run, empty folder. Set
fallback_modetopassthroughand wire a start image, or you'll get black/error frames. - Everything upstream re-runs. Remember the always-dirty behavior. If the graph feels slow and this node is in it, that's why.
For iterative and auto-queue pipelines, this is the linchpin node - the one that turns "generate once" into "generate forever." It's fiddly to set up and deeply worth it.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| folder_path | STRING | Absolute or relative path to the folder containing images. Created if missing. | |
| extensionsopt | STRING | png,jpg,jpeg,webp,tiff,bmp | Comma-separated image extensions to match |
| fallback_modeopt | COMBO | passthrough | What to return when folder is empty. passthrough = use the fallback_image input. black = 512x512 black. error = raise exception |
| sort_byopt | COMBO | mtime | mtime = newest modified file. name = highest natural-sorted filename |
| filename_filteropt | STRING | Optional substring filter on filenames (e.g. "megawarp_"). Empty = all | |
| fallback_imageopt | IMAGE | Image to return when folder is empty and fallback_mode is 'passthrough' |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | The most recently modified image (or fallback) |
| frame_count | INT | Total number of matching files in the folder (use as next frame index) |
| found | BOOLEAN | True if a real image was loaded, False if the fallback was returned |
| filename | STRING | Basename of the loaded file (empty if fallback) |