ComfyUI Node

Image From Folder (Index)

Load image number N from a folder — the loop-friendly way

By vrgamegirl19·Created about a year ago·Updated about 21 hours ago· 682
Image From Folder (Index)
    • image
    folder_path
    index0
    random_after_endfalse

    Sometimes you don't want to pick an image in the UI - you want the graph to pick it for you, one per loop iteration. That's what this node is for: it loads a single image from a folder by index, so a workflow that runs in chunks can pull a different reference image each time it executes. In the VRGameDevGirl music-video pipeline it's how per-scene reference frames get driven by the loop counter instead of by your mouse.

    The behavior is simple and predictable. Files are collected from folder_path, sorted by the first number found in the filename (so frame_001.png before frame_002.png, regardless of string ordering), and index selects which one loads. Index 0 is the first image, not the first frame of a video.

    What the knobs do

    • folder_path - the directory. It must exist and contain at least one image (png, jpg, jpeg, webp, bmp, tiff are all fine). Missing folder or no images throws a clear error.
    • index - which image to load, zero-based.
    • random_after_end - the interesting one. Normally the index wraps around with modulo, so index 12 on a 10-image folder loads image 2. With random_after_end on, once the index passes the end of the list it picks a random image instead of looping, with a guard: it won't repeat either of the last two picks. That gives you variety without the same two frames bouncing back and forth.

    Output is a single image (IMAGE tensor) ready to wire into a VAE encode or a sampler as conditioning. Nothing else.

    Where it fits

    If you're looping a workflow over scenes, wire your loop index into index and you get deterministic per-iteration reference images. random_after_end is the trap to watch: it changes behavior after the last index, so a loop that's supposed to wrap cleanly will suddenly start showing random frames once you exceed the count. That's the feature - it's for "loop infinitely but keep it fresh" mode - but if your loop index legitimately cycles past the end, leave it off and rely on the modulo wrap.

    Install

    Same pack, same install: ComfyUI Manager → search "vrgamedev", or git clone https://github.com/vrgamegirl19/comfyui-vrgamedevgirl into ComfyUI/custom_nodes, restart. No extra dependencies beyond what the pack already needs, no models. One filename-sorting quirk worth knowing: files whose names contain no number at all sort to the end (treated as infinity), so name your reference frames with numbers if you want order to mean anything.

    Categoryimage

    Inputs (3)

    NameTypeDefaultDescription
    folder_pathSTRING
    indexINT0
    random_after_endBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    imageIMAGE