Get File Count
Count the images in a folder, then drive a batch loop off the number
- count
- folder
- filename
- file_path
- include_subdir
Processing a folder full of images is a classic ComfyUI pain point: the batch loop needs to know how many files exist, and hardcoding "7 images" is how workflows rot. Get File Count (1hew_GetFileCount) answers "how many files of this type are in this folder" as a real INT, and throws in the file lists for good measure.
It lives in the 1hewNodes/io group of the 1hewNodes pack, next to the folder-loading nodes it's meant to feed (Load Image From Folder, Load Video From Folder, and the newer Load PS).
How it works
You give it a folder path and a type, and it walks the folder collecting files with the matching extensions:
- image - png, jpg, jpeg, bmp, tiff, webp
- video - webm, mp4, mkv, gif, mov, avi
- psd - psd
- txt - txt
include_subdir (default on) recurses into subfolders; turn it off for top-level only. Paths are sorted case-insensitively so the order is stable across platforms - important when you're pairing the count with an index-based loader and need frame N to always be the same file. There's also a proper IS_CHANGED implementation: it hashes the list of file paths, so if you add or delete files, the node re-runs and the count updates. It doesn't poll your workflow with phantom re-runs when nothing changed.
Inputs and outputs
- folder - the directory to scan.
- type - image / video / psd / txt.
- filename_suffix - off returns base names without extensions; on keeps the extension in the
filenamelist. - include_subdir - recurse or not.
- count - the
INTyou'll wire into loops. - folder - echoes the input path.
- filename (list) - just the names.
- file_path (list) - full paths.
- include_subdir - echoed back.
The duplicated folder/include_subdir outputs look odd, but they're handy for passing a folder value downstream without a separate string node.
Installing it
Part of the 1hewNodes pack:
cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes
or via ComfyUI Manager ("1hewNodes"), then restart. No models.
Where it earns its keep
The canonical pattern: Get File Count → count into a batch loop → Load Image From Folder (or the pack's folder loader) processes every file, with the count keeping the loop honest. It's also quietly useful for txt/psd if you're batch-captioning or batch-editing layered files, and for any workflow that needs to know "is this folder empty?" before proceeding.
The one thing it won't do is watch the folder and react - it's not a hot-reloader, it re-runs when you re-run the workflow (or when its IS_CHANGED hash changes, which effectively means when the file list changes on your next run). For a batch-processing setup, that's exactly right. If you're coming from a node that counts in real time, adjust expectations: this is count-on-request, and that's what you want.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| folder | STRING | — | |
| type | COMBO | image | 4 options: image, video, psd, txt |
| filename_suffix | BOOLEAN | false | — |
| include_subdir | BOOLEAN | true | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| count | INT | — |
| folder | STRING | — |
| filename | STRING | — |
| file_path | STRING | — |
| include_subdir | BOOLEAN | — |