ComfyUI Node

Load Filtered Image Batch

Load every image in a folder as one batch — without building twenty load nodes

By McKlinton2·Created about a year ago·Updated about a year ago· 6
Load Filtered Image Batch
    • images
    • root_dir
    • filenames
    folder
    filter

    This is the unglamorous workhorse of the McKlinton Pack: point it at a folder, get every matching image back as a single batched IMAGE tensor. No per-image load nodes, no drag-and-drop, no fuss. It's one of those nodes you don't think about until you're batch-processing a directory of renders and realize core ComfyUI has no clean "load this whole folder" button.

    It's the second node in the pack (category McKlinton/load), and the pack's framing is all about Virt-A-Mate scene exports - color, depth, mask, and prompt files that all share a base name. So the natural use is dumping a folder of VAM snapshots into an img2img or ControlNet batch loop. But honestly it works fine on any image folder, VAM or not.

    How it works

    Two inputs, that's it. folder is a path; filter is a regex applied to filenames (empty means "load everything"). The node lists the directory, keeps files ending in .jpg, .jpeg, .png, .webp, or .bmp, runs re.search(filter, filename) on each, sorts the survivors for a stable order, and loads them all.

    Each image gets the EXIF orientation fix, gets converted to RGB, normalized to 0–1 floats, and stacked into one tensor via torch.cat. You get three outputs:

    • images - the whole folder as a single batched IMAGE. Wire it into a sampler batch, an img2img node, or a batch-processing subgraph.
    • root_dir - the folder path you passed in, passed back out as a string. Convenient for feeding the save side of a workflow.
    • filenames - a list of strings, and the reason you might actually pick this node over alternatives. Each name is stripped to the last underscore-delimited token: anything_1231231314512.png becomes 1231231314512. That's not a typo, it's the VAM snapshot convention - the timestamp that groups a color/depth/mask/prompt set together.

    That filenames output is the clever bit, because the pack's save node (SaveTextArrayToFiles) accepts exactly that shape. Load a folder, process the batch, save the results back under the same names - a tidy round trip that's otherwise fiddly to wire.

    Install

    Same pack, same drill - via ComfyUI Manager (search the pack title) or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/McKlinton2/comfyui-mcklinton-pack
    # restart ComfyUI
    

    No model files, no GPU weight downloads. It only needs Pillow, numpy, and torch - all already in your ComfyUI env. The pack's requirements.txt does list three OpenCV variants which is pure redundancy; you don't need any of them for this node.

    Where people get burned

    • Mixed resolutions will crash it. torch.cat needs every image the same H×W, so a folder with a stray 800×600 in a sea of 1024×1024 kills the whole batch with a shape error. Size the folder first.
    • The filter is a raw regex on the full filename, extension included. filter = "color" matches color_001.png, but so does filter = "lor_00". There's no escaping or anchoring, so be deliberate.
    • No matches = hard error. It raises ValueError("No matching image files found") rather than returning an empty batch. A typo'd folder path or filter silently blows up the graph, which is confusing the first time because there's no visible failure - the node just goes red.
    • Don't assume filenames lines up with images. The node sorts the file list before loading, but it captures the base names before sorting, in raw directory-listing order. On most filesystems those two orders agree, but it's not guaranteed - so if you pair the names with the batch downstream (the pack's save node happily does), spot-check the order once, especially after a folder re-organization.

    It's a small node, and its job is small. But when you need "every file in this directory, as one batch, with its names intact," there's nothing else in the pack that does it, and it's the exact missing link for the pack's save node.

    CategoryMcKlinton/load

    Inputs (2)

    NameTypeDefaultDescription
    folderSTRING
    filterSTRING

    Outputs (3)

    NameTypeDescription
    imagesIMAGE
    root_dirSTRING
    filenamesSTRING