Nodes/ComfyUI Level Pixel/Get Iterator Data From Image Folders [LP]
ComfyUI Node

Get Iterator Data From Image Folders [LP]

Get Iterator Data From Image Folders [LP] — ComfyUI Node Guide

By LevelPixel·Created 2 years ago·Updated 6 months ago· 31
Get Iterator Data From Image Folders [LP]
    • iterator_data
    • folder_count
    • image_count
    directory_path
    patterns*.jpg|*.png|*.jpeg
    subfolder
    rescan_each_queuetrue

    If you've got a directory full of subfolders - one per character, one per shoot, one per dataset split - and you want ComfyUI to work through them automatically, this is the node that scans the folder tree and hands the rest of the LevelPixel iterator nodes something to count through. It doesn't load a single pixel itself. Its job is purely reconnaissance: walk the directory, find the image folders, tell you how much is in there.

    What it's for

    This slots into the same "ComfyUI doesn't have a real for-loop, so we build one out of the queue" pattern as Iterator and ImageDataIterator in this pack. You point it at a root directory, it scans for subfolders matching your patterns, and it hands off an iterator_data bundle that ImageDataIterator then reads one entry at a time as you queue the workflow repeatedly. Think of it as the "here's the manifest" step before the "give me item #N" step.

    Where this actually earns its keep: batch dataset prep. If you're organizing LoRA training folders (one subfolder per subject, images inside each) and you need to run something - a resize pass, a captioning step, a watermark check - across every image in every folder without touching each one by hand, this is the discovery layer that makes that loop possible.

    Inputs and outputs

    • directory_path (STRING) - the root folder to scan.
    • patterns (STRING, default *.jpg|*.png|*.jpeg) - the file extensions it'll look for, pipe-separated. Add *.webp or drop a format if you don't need it.
    • subfolder (STRING) - narrow the scan to a specific subfolder under directory_path instead of the whole tree.
    • rescan_each_queue (BOOLEAN, default true) - whether it re-walks the directory on every queue run. Leave this on if you're adding or removing files mid-session; turn it off if the folder is static and you want to save the filesystem hit on every single queue.

    Outputs: iterator_data (its own ITERATOR_DATA type - only wires into nodes built to read it, like ImageDataIterator), folder_count (INT), image_count (INT). The two counts are the useful bit for setting up your loop bounds - feed image_count into whatever limit you're comparing your running index against.

    Installing it

    ComfyUI Manager: search "ComfyUI-LevelPixel" (listed as "Level Pixel") and install. Manual route: cd ComfyUI/custom_nodes && git clone https://github.com/LevelPixel/ComfyUI-LevelPixel.git, restart ComfyUI. Nothing to download beyond the node code itself - no model weights, no GPU-hungry dependency, it's just filesystem scanning in Python.

    Common issues

    directory_path needs to be a real, reachable path from wherever ComfyUI's process actually runs - if you're on Docker, in Modal, or any containerized setup, "the folder I see in Explorer" and "the folder ComfyUI's process sees" can be two different filesystems entirely. Double check the path resolves inside the container/environment ComfyUI is actually running in, not just on your desktop.

    The patterns field is easy to get wrong the first time because it's pipe-separated, not comma-separated - *.jpg,*.png silently won't match anything, *.jpg|*.png will. And if rescan_each_queue is off and you're not seeing new files you just added, that's not a bug, that's the setting doing exactly what it says - flip it back on or restart the workflow to force a fresh scan.

    Since iterator_data is a custom type, it only connects to sockets built for it - you can't route it into a generic input expecting STRING or INT. If a wire won't connect where you expect, check you're actually feeding it into ImageDataIterator and not something further downstream that wants the resolved image itself.

    CategoryLevelPixel/Iterators

    Inputs (4)

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

    Outputs (3)

    NameTypeDescription
    iterator_dataITERATOR_DATA
    folder_countINT
    image_countINT