Nodes/ComfyUI Easy Use/imagesCountInDirectory
ComfyUI Node Runs on cloud

imagesCountInDirectory

How many images are in that folder

By yolain·Created 3 years ago·Updated 8 days ago· 2,633
imagesCountInDirectory
    • count
    directory
    start_index0
    limit-1

    You want to batch-process a folder of images - run every picture in input/photos/ through the same workflow. To loop over them, you first need to know how many there are, so the loop knows when to stop. easy imagesCountInDirectory answers that one question: point it at a folder, get back the number of images in it.

    It's a plumbing node from yolain's ComfyUI-Easy-Use pack, and on its own it's almost boring. Its whole reason to exist is the node next to it in a loop - you feed the count into a for-loop as the iteration count, then load and process one image per pass.

    How it works

    Give it a directory path and it counts the image files there and returns a single integer. Nothing gets loaded into memory - it's just counting filenames, so it's fast even on a big folder.

    Two extra inputs let you count a slice rather than the whole thing:

    • start_index - skip the first N files. Handy for resuming a batch that died partway, or ignoring a header image.
    • limit - cap how many you count. Default is -1, which means "no cap, count everything." Set it to, say, 50 to process only the first fifty.

    So the effective count is "files from start_index onward, up to limit."

    Inputs and outputs

    • directory - the folder path. Use a path the ComfyUI process can actually read.
    • start_index / limit - optional trimming, as above.

    The output is count, one INT. In practice it goes straight into the count/end input of a for-loop (EasyUse's own forLoopStart/forLoopEnd, for instance), and the loop body uses the running index to load image number 0, 1, 2… typically via a load-image-by-index node like easy loadImageForLoop.

    Installing it

    It ships with the pack. ComfyUI Manager → "ComfyUI Easy Use" → install → restart. Or by hand: cd ComfyUI/custom_nodes && git clone https://github.com/yolain/ComfyUI-Easy-Use, then install.bat / pip install -r requirements.txt, restart.

    Common issues

    The number-one problem is the path. ComfyUI runs as its own process, and it needs a path it can see - an absolute path, or one relative to where ComfyUI is running, not relative to wherever you happen to be in a terminal. On a hosted or containerized setup the folder has to actually exist inside that environment. A count of 0 almost always means "wrong path" or "folder empty," not a bug in the node.

    Second, remember what "images" means here - it counts image files, so non-image junk in the folder (a stray .txt, a Thumbs.db) shouldn't inflate the number, but a folder full of, say, videos will read as fewer images than files. And if your limit is set and you're wondering why the count caps out lower than the real total - that's the limit doing its job, not a miscount.

    CategoryEasyUse/Image

    Inputs (3)

    NameTypeDefaultDescription
    directorySTRING
    start_indexINT0
    limitINT-1-1–10000

    Outputs (1)

    NameTypeDescription
    countINT