Nodes/ComfyUI-KYNode/File Sequence Analyzer
ComfyUI Node

File Sequence Analyzer

Reverse-engineer a numbering template from one filename

By yorkane·Created 2 years ago·Updated 6 months ago· 10
File Sequence Analyzer
    • sequence_pattern1
    • start_number1
    • sequence_pattern2
    • start_number2
    file_pathimage_001_v02.png

    A oddly specific, genuinely handy little node: give it one example filename from a render batch - say image_001_v02.png - and it works out the numbering pattern hiding in it, so you don't have to hand-count digits when setting up something like KY_SaveImageToPath's filename template.

    How it works

    You type a single filename into file_path - not a folder, one string - and the node scans it for runs of digits. It picks the two longest digit runs it finds (not the first two, the longest two) and converts each into a #-padded template that preserves the original digit width.

    The node's own documented example makes the "longest, not leftmost" behavior clear: shot05_take003.jpg becomes sequence_pattern1 = shot##_take###.jpg with start_number1 = 3, and sequence_pattern2 covering the shorter shot05 run with start_number2 = 5 - even though shot05 appears earlier in the string, take003's three-digit run outranks its two-digit run and comes first in the output. The other documented example, image_001_v02.png, splits into image_###_v02.png (from 001, three digits) as pattern 1 and image_001_v##.png (from 02, two digits) as pattern 2.

    Inputs and outputs

    One input: file_path (a string, default image_001_v02.png). Four outputs: sequence_pattern1 and start_number1 for the longest digit run found, sequence_pattern2 and start_number2 for the second-longest.

    Installing it

    ComfyUI Manager: search ComfyUI-KYNode, install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/yorkane/ComfyUI-KYNode
    

    Restart ComfyUI. Pure string parsing, no external dependencies. This is a small personal-toolbox pack - the README is a bare feature list and there's no meaningful discussion of it anywhere in the wider ComfyUI community - so this is a niche utility you'll mostly find by needing exactly this, not by seeing it recommended.

    Common issues

    The biggest thing to get right is that this node analyzes one filename you type in, not a directory - it doesn't scan a folder for you and find the real numbering pattern across many files. You have to supply a representative example filename yourself.

    If your filename has fewer than two digit runs - say, just render_042.png with a single numeric group - expect the second pattern/number pair to come back empty or at its defaults rather than populated, since there's nothing for it to find.

    And because it ranks by digit-run length rather than position, don't assume sequence_pattern1 always corresponds to whichever number comes first when reading the filename left to right - as the shot##_take### example shows, a shorter number earlier in the string can lose out to a longer one later in it. If you need the first number specifically rather than the longest, check both outputs before wiring one downstream.

    CategoryKYNode/files

    Inputs (1)

    NameTypeDefaultDescription
    file_pathSTRINGimage_001_v02.png

    Outputs (4)

    NameTypeDescription
    sequence_pattern1STRING
    start_number1INT
    sequence_pattern2STRING
    start_number2INT