Nodes/TrentNodes/Get Latest Image From Folder
ComfyUI Node

Get Latest Image From Folder

Feed the Last Render Back Into the Loop

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
Get Latest Image From Folder
  • fallback_image
  • image
  • frame_count
  • found
  • filename
folder_path
extensionspng,jpg,jpeg,webp,tiff,bmp
fallback_modepassthrough
sort_bymtime
filename_filter

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:

  1. Scans for files matching extensions (default png,jpg,jpeg,webp,tiff,bmp), optionally filtered to names containing filename_filter (e.g. "megawarp_" to only loop over your real frames and skip stray saves).
  2. Picks the newest by sort_by: mtime (default, newest modified file) or name (highest natural-sorted filename).
  3. 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_filter is for.
  • First run, empty folder. Set fallback_mode to passthrough and 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.

CategoryTrent/Video

Inputs (6)

NameTypeDefaultDescription
folder_pathSTRINGAbsolute or relative path to the folder containing images. Created if missing.
extensionsoptSTRINGpng,jpg,jpeg,webp,tiff,bmpComma-separated image extensions to match
fallback_modeoptCOMBOpassthroughWhat to return when folder is empty. passthrough = use the fallback_image input. black = 512x512 black. error = raise exception
sort_byoptCOMBOmtimemtime = newest modified file. name = highest natural-sorted filename
filename_filteroptSTRINGOptional substring filter on filenames (e.g. "megawarp_"). Empty = all
fallback_imageoptIMAGEImage to return when folder is empty and fallback_mode is 'passthrough'

Outputs (4)

NameTypeDescription
imageIMAGEThe most recently modified image (or fallback)
frame_countINTTotal number of matching files in the folder (use as next frame index)
foundBOOLEANTrue if a real image was loaded, False if the fallback was returned
filenameSTRINGBasename of the loaded file (empty if fallback)