Nodes/ComfyUI-ZhiHui/📂 智绘_子文件夹批量加载 (V3 终极版)
ComfyUI Node

📂 智绘_子文件夹批量加载 (V3 终极版)

Walk a tree of folders and pull a slice of images out of each

By zhuyungen·Created 8 months ago·Updated 3 months ago· 0
📂 智绘_子文件夹批量加载 (V3 终极版)
    • images_batch
    • folder_names
    folder_path
    seed0
    load_modeIndex (按索引顺序)
    start_index0
    folder_limit1
    image_start_index0
    image_per_folder1
    resize_modePad (填充-推荐)
    target_width0
    target_height0

    Flat-folder loaders are everywhere. ZH_SubfolderLoader_V3 ("📂 智绘_子文件夹批量加载 (V3 终极版)") is the one that works two levels deep: you give it a root directory full of subfolders, tell it how many subfolders to visit and how many images to grab from each, and it assembles one batch from across the tree. That's the shape of a real dataset - class folders, scene folders, per-job folders - and it's the missing piece when your images are organized, not just dumped.

    It's from ComfyUI-ZhiHui, a Chinese-language utility pack. The "V3 终极版" (ultimate edition) naming tells you this node has been iterated on a few times, and its own docstring claims the seed parameter exists to fix ComfyUI's "won't swap images" cache problem.

    How it works

    Scan the root for subfolders, sort them, and apply your slicing rules. In Index mode (default) it takes subfolders[start_index : start_index + folder_limit]; in Random mode it uses the seed to shuffle and sample folder_limit subfolders. Within each selected folder it grabs image_per_folder images starting at image_start_index. Everything collected then gets normalized to a single size and stacked into one batch.

    The size rules mirror the pack's flat loader: target_width/target_height of 0 mean "follow the first image," and the resize_mode dropdown handles mismatches - Pad (填充-推荐) letterboxes, Crop center-crops, Stretch distorts, and Disabled errors out on any size mismatch (useful when you want to be told your data is inconsistent).

    Outputs: images_batch (IMAGE) and folder_names (STRING - the subfolder names you sampled from, comma-joined), which is handy for knowing which class of data you just pulled.

    The inputs that matter

    • folder_path - the root directory (raw OS path).
    • load_mode, seed - indexed walk or seeded random sample.
    • start_index, folder_limit - which and how many subfolders.
    • image_start_index, image_per_folder - which and how many images per subfolder.
    • resize_mode, target_width, target_height - the batch-size policy.

    Install

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

    Restart ComfyUI. Base deps only, no models. ComfyUI Manager search "ComfyUI-ZhiHui" also works.

    Where people get burned

    Here's the honest one: the docstring boasts that the seed busts the ComfyUI cache and forces new images on every run, but reading the shipped source, the seed isn't actually wired into an IS_CHANGED hook - the classic cache-killer (returning NaN from IS_CHANGED, per the plumbing rules) isn't there. So if you hit "it keeps showing the same images," changing the seed won't fix it; nudge another input or restart the queue. Second, index mode loops the start index when it exceeds the subfolder count (modulo), which silently revisits folders instead of stopping - a "finished" batch can start repeating data without warning. And folder sorting is plain alphabetical, so numeric folder names sort as strings (folder10 before folder2); zero-pad your names if order matters.

    Category智绘灵箱/图片

    Inputs (10)

    NameTypeDefaultDescription
    folder_pathSTRING
    seedINT00–18446744073709550000
    load_modeCOMBOIndex (按索引顺序)2 options: Index (按索引顺序), Random (随机抽取)
    start_indexINT00–10000
    folder_limitINT11–100
    image_start_indexINT00–10000
    image_per_folderINT11–100
    resize_modeCOMBOPad (填充-推荐)4 options: Disabled (报错), Stretch (拉伸), Crop (裁剪), Pad (填充-推荐)
    target_widthINT00–40960 = 跟随第一张图
    target_heightINT00–40960 = 跟随第一张图

    Outputs (2)

    NameTypeDescription
    images_batchIMAGE
    folder_namesSTRING