Nodes/ComfyUI-My-Nodes/文件计数器
ComfyUI Node

文件计数器

Count the files in a folder so your batch loop knows when to stop

By Tagbliton·Created 2 years ago·Updated about a year ago· 11
文件计数器
    • 文件数量
    • 统计信息
    folder_path./input
    include_subfoldersfalse
    file_extensions*

    The boring truth about batch workflows: they only work if you know how many items you're processing. This node is the answer to that question - point it at a folder, and it tells you how many files are in it. One INT output with the count, plus a STRING with a human-readable stats summary. Feed that INT into a loop's max iterations and your batch sizes itself to whatever's actually in the folder, which is a genuinely nice quality-of-life upgrade over hardcoding a number that goes stale the moment you add a file.

    The inputs: folder_path (a string, default ./input - so it points at ComfyUI's input folder out of the box, and the tooltip just says "folder path"), plus two optional refinements. include_subfolders (boolean, default off) makes the scan recursive; turn it on for nested trees. file_extensions (string, default *) filters what counts - a comma-separated list like png,jpg,txt counts only those types, * counts everything. The node validates that the path exists and is a directory, and raises a clear error if it isn't, rather than silently returning 0.

    Outputs: 文件数量 (the INT count) and 统计信息 (a STRING block summarizing path, scan mode, and file-type filter - nice for a text-log node if you want a paper trail of what a run processed).

    Mechanically it's an os.scandir walk with an extension filter, and the README's stated purpose is exactly the loop use case: feed 文件数量 into a for-loop's end condition, so the loop iterates once per file. Wire it with the pack's "提示词逐行读取" and you've got a folder-driven batch pipeline that adapts as you drop files in.

    Install: part of ComfyUI-My-Nodes - ComfyUI Manager → search "ComfyUI-My-Nodes", or git clone https://github.com/Tagbliton/ComfyUI-My-Nodes into custom_nodes and restart. Pure local utility - no API key, no network, none of the DashScope account stuff.

    Gotchas. Three small ones. First, ./input is relative to ComfyUI's base directory - if your folders live elsewhere, give the full path or the node errors with "路径不存在" (path doesn't exist). Second, the extension filter compares against the last dot-segment of the filename, so png matches photo.png but not photo.png.txt. Third, the count includes hidden files and any stray temp files in the folder - if the number looks one higher than you expect, check for an OS-generated file like .DS_Store or a Thumbs.db. If those pollute your count, the file_extensions filter is the clean fix.

    Category我的节点/Tools

    Inputs (3)

    NameTypeDefaultDescription
    folder_pathSTRING./input文件夹路径
    include_subfoldersoptBOOLEANfalse是否包含子文件夹
    file_extensionsoptSTRING*计数文件格式,如png、jpg、txt,*表示所有文件

    Outputs (2)

    NameTypeDescription
    文件数量INT
    统计信息STRING