Nodes/ComfyUI Level Pixel/File Counter [LP]
ComfyUI Node

File Counter [LP]

Counting matching files in a folder

By LevelPixel·Created 2 years ago·Updated 5 months ago· 31
File Counter [LP]
    • Total INT
    • Total STRING
    directory_path
    patterns*.jpg|*.png|*.jpeg
    rescan_each_queuetrue

    The README calls it "a simple counter of files in a given folder. Convenient when you need to count the number of files in a certain format (for example, for subsequent use in loops or conditions)." That's the whole node in one sentence - point it at a folder, get back how many files match, and use that number to drive whatever comes next.

    Why you'd want this

    This pairs directly with the pack's folder-walking nodes: if you're stepping through a directory one file at a time by index (this pack's GetFilenameByIndexInFolder-LP, for instance), you need to know how many files actually exist before your loop counter walks past the end of them. Real automation workflows built around this pack - folder-driven, run-in-a-loop pipelines that process a batch of images end to end - lean on exactly this kind of pre-flight count to size the loop correctly instead of guessing or hardcoding a number.

    The inputs and outputs that matter

    • directory_path - the folder to scan, plain text, no default.
    • patterns - a pipe-delimited set of glob patterns, default *.jpg|*.png|*.jpeg. Add more patterns by separating them with |, not commas.
    • rescan_each_queue - a BOOLEAN, default True. Left on, the node re-scans the folder fresh every single time you queue the workflow rather than relying on ComfyUI's normal caching of unchanged inputs - the setting to reach for when files are being added or removed by another part of your pipeline (or externally) between runs.
    • Outputs: Total INT (the count, for driving loop logic) and Total STRING (the same number as text, for display or logging).

    Worth noting: this node is marked as an output node in its own schema, meaning it can execute and show you a result on its own, even without wiring its outputs anywhere else - handy if you just want a quick file count without building further logic around it.

    How to install it

    ComfyUI Manager: search "ComfyUI Level Pixel" or ComfyUI-LevelPixel, install, restart - updates automatically via Manager's "Update ALL." Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/LevelPixel/ComfyUI-LevelPixel.git
    

    Restart ComfyUI. No models, nothing else needed - it's reading the filesystem directly.

    Common issues & troubleshooting

    The count doesn't match what you see in the folder. Check patterns first - it's a pipe-delimited glob list, and a typo there (a stray space, a wrong extension) silently excludes files rather than erroring. Also worth checking case sensitivity: depending on your OS and filesystem, *.JPG (uppercase extension) may or may not match a lowercase *.jpg pattern.

    The count is stale after your pipeline just wrote new files to that folder. Make sure rescan_each_queue is True. With it off, you may be getting a cached result from ComfyUI's normal execution-caching behavior rather than a fresh read of the folder's current contents.

    You want to loop through the files this counts, not just know how many there are. Pair this with the pack's GetFilenameByIndexInFolder-LP - use this node's Total INT output to know your loop's upper bound, then step through indices with that node to actually retrieve each filename.

    CategoryLevelPixel/IO

    Inputs (3)

    NameTypeDefaultDescription
    directory_pathSTRING
    patternsSTRING*.jpg|*.png|*.jpeg
    rescan_each_queueBOOLEANtrue

    Outputs (2)

    NameTypeDescription
    Total INTINT
    Total STRINGSTRING