Nodes/Arkl1te's Toolkit/Count Files In Directory
ComfyUI Node

Count Files In Directory

The live counter that makes batch video filenames sane

By arkl1te·Created 11 months ago·Updated 10 months ago· 1
Count Files In Directory
    • INT
    directoryvideo
    extensionmp4

    If you render videos in batches - LTX, Wan, whatever your pipeline is - you know the pain of the second run clobbering the first. Count Files In Directory exists to stop that. It counts how many files with a given extension sit in a folder and hands you the number as an INT, so you can compute "what should the next clip be called" before you save anything. The defaults tell you exactly who it's for: directory defaults to video, extension defaults to mp4.

    Mechanically it's dead simple and refreshingly honest. It resolves your directory relative to ComfyUI's output folder (so video means ComfyUI/output/video), lowercases the extension, and counts matching files directly in that folder. Crucially, the node sets IS_CHANGED to a random value every run, which in ComfyUI-speak means it is never cached - it re-executes on every queue run and gives you a live count. That's the difference between this and a node whose count goes stale. If the folder doesn't exist yet, it returns 0 instead of erroring, which is a nice touch for first runs.

    Two inputs, one output. directory is a STRING with a browse button (file_select - it opens a real folder picker), defaulting to video. extension is a STRING, default mp4, and the match is case-insensitive (.MP4 counts). Output is an INT.

    Now the caveats, because "count" and "next filename index" are not the same thing. It counts files that exist right now - it does not reserve a number for you. Delete a clip from the folder and the count drops, so the next save could collide with an existing name. It's non-recursive: only files directly in the folder, not in subfolders. And on Windows the path handling swaps slashes internally, which is fine until you try to use the output for anything cross-platform. For the common case - an output folder that only ever grows - count + 1 is a perfectly safe index.

    That "next index" purpose is literally what the node used to be called: GetNewFileIndex. The rename came because the old name oversold it - it never computed a "new" index, it just counted. The pack still registers the old name as an alias, so if you load an old workflow that references GetNewFileIndex it keeps working. You'll see both names in the node menu, which is mildly confusing; just use Count Files In Directory and let the alias be.

    The canonical workflow: Count Files In Directory → Pad Zeroes (turn 7 into 0007) → Concatenate (build video_0007.mp4) → Save Video. Three tiny nodes, and suddenly every batch run names itself instead of overwriting.

    Install: search "Arkl1te's Toolkit" in ComfyUI Manager, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/cybernaut4/comfyui_arkl1te_toolkit
    

    Restart ComfyUI. The pack has zero Python dependencies - no requirements.txt, no models to download - so there's nothing extra to install and nothing to conflict with your other nodes. If your count ever looks wrong, first check whether you're pointing at output-relative paths (it can't see arbitrary absolute folders), then check that the folder exists and the extension is spelled right.

    CategoryArkl1te's Toolkit/int

    Inputs (2)

    NameTypeDefaultDescription
    directorySTRINGvideo
    extensionSTRINGmp4

    Outputs (1)

    NameTypeDescription
    INTINT