Nodes/Nilor Nodes by Nilor Corp/๐Ÿ‘บ Count Images In Directory
ComfyUI Node

๐Ÿ‘บ Count Images In Directory

How many PNGs are in this folder? One INT, no surprises

By nilor-corpยทCreated 2 years agoยทUpdated 5 months agoยท 6
๐Ÿ‘บ Count Images In Directory
    • int
    โ—„directoryX://path/to/imagesโ–บ

    Batch workflows love knowing how much work there is before they start. If you're pointing ComfyUI at a folder full of images, you usually want to know the count first - to size a loop, set a batch limit, or sanity-check that the folder actually has content. Nilor Count Images In Directory is the one-line answer: feed it a directory path, get back an integer. It's aggressively simple, and that's a feature.

    What it does

    One required input, directory (default X://path/to/images - note the Windows-style placeholder, but any path your OS understands works). It lists the directory and counts files whose names end in .png, .jpg, or .jpeg. The int output is that count.

    The details that will bite you

    It's not recursive. Only the immediate folder is scanned - subdirectories are ignored. If your images live in nested folders, the count will be short and the node won't tell you.

    The extension check is case-sensitive and lowercase-only. photo.PNG and photo.JPG will not be counted, because the source checks file.endswith(".png") and friends directly. Files saved by some Windows tools or cameras with uppercase extensions will silently vanish from your count. If you're seeing a count lower than expected, this is the first thing to check.

    Missing directory = hard error. If the path doesn't exist, the node raises a FileNotFoundError and the whole run stops. It's a clean, descriptive error - but it means you can't use this node to probe "is this folder there?" without killing the run. Use it only on paths you've verified, or wrap the workflow so a missing folder is expected.

    Only those three extensions. WebP, GIF, BMP, TIFF, HEIC - all ignored. The sibling node ๐Ÿ‘บ Load Image By Index reads a much wider set of formats (including webp, bmp, gif), so it's entirely possible for the two to disagree about how many images a folder holds. That mismatch has probably cost someone an hour already.

    Where it fits

    The natural pairing is with ๐Ÿ‘บ Load Image By Index: count the folder, feed that count (or a derived index list from ๐Ÿ‘บ List of Ints) into the loader's seed-as-index mechanism, and you have a folder-scanning batch pipeline. It's also handy as a workflow gate - a counter that stops or branches when a folder reaches a target size.

    Install

    ComfyUI Manager (search "Nilor Nodes") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/nilor-corp/nilor-nodes
    cd nilor-nodes && pip install -r requirements.txt
    

    Restart ComfyUI; it's under Nilor Nodes ๐Ÿ‘บ โ†’ Utilities. No dependencies - just os.listdir under the hood.

    Bottom line

    A dead-simple counter that does one job and refuses to do it loosely. The limitations (no recursion, lowercase-only extensions, three formats, hard error on missing dirs) are all worth knowing before you trust its output as the truth about a folder. For a well-formed folder of lowercase .png/.jpg files, it's perfect and boring. For anything messier, treat the number as a lower bound and verify.

    CategoryNilor Nodes ๐Ÿ‘บ/Utilities

    Inputs (1)

    NameTypeDefaultDescription
    directorySTRINGX://path/to/imagesโ€”

    Outputs (1)

    NameTypeDescription
    intINTโ€”