Nodes/Comfyui_JTnodes/JT Serial Counter
ComfyUI Node

JT Serial Counter

Zero-pad numbers into filenames without the arithmetic

By Jint8888·Created about a year ago·Updated about a year ago· 1
JT Serial Counter
    • STRING
    number1
    digits4

    JT Serial Counter is the least glamorous node in the pack, and one of the more useful ones. It takes an integer and turns it into a zero-padded string: give it 7 with four digits and you get 0007. That's the whole job. No model, no API, no state, just text formatting - which is exactly why it's handy in batch workflows.

    Why you'd reach for it

    Once you start generating in bulk, you hit the filename problem. img_1.jpg, img_2.jpgimg_10.jpg sorts wrong everywhere - Windows Explorer, your cloud upload, your hard drive, all of them put img_10 right after img_1. Padding fixes that: img_0001 through img_0010 sorts correctly forever. This node gives you that padding as a plain STRING output you can drop into a filename builder, a prompt assembler, or the save nodes elsewhere in this pack.

    It's also handy for numbering prompts rather than files. If you're generating a variation series and want each run labeled "sample 0001" inside the metadata, or you're building a sequential set of filenames to match an Excel row index, a string you can concatenate is more useful than a raw int.

    How it works

    Two inputs in, one string out:

    • number (INT) - the value to format, 0 to 99999.
    • digits (INT) - the target width, 1 to 5, default 4.

    The output is number formatted with leading zeros to your requested width. There's one bit of behavior worth knowing before it bites you: digits is a floor, not a hard cap. The node compares your requested width against how many digits the number actually needs and uses whichever is bigger. So with digits = 4 and number = 12345, you get 12345, not 1234 or a crash. The README calls this "intelligent digit adjustment," which is a fancy way of saying it never truncates. If you want strictly padded output, keep your numbers inside the range the width can hold.

    The output is a single STRING, ready to wire into any text input - a filename node, a concat node, a prompt template.

    Fitting it into a workflow

    The natural pairing is with JT Save Image to Path, which has its own use_counter toggle that does the padding internally. But this node wins when you want the number before it's baked into a filename - say, to keep an index in sync between a spreadsheet and your outputs, or to feed the same sequence into several places at once. Wire a number from any INT source (a loop index, another node's count output) and you're set.

    Installing it

    Same deal as every node in this pack - it ships inside Comfyui_JTnodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Jint8888/Comfyui_JTnodes
    pip install "openai>=1.0.0" "openpyxl>=3.0.0"
    

    or find "Comfyui_JTnodes" in ComfyUI Manager. Do not skip that pip install - the repo has no requirements.txt, and because the pack imports openai at load time, missing dependencies take down the entire pack, not just the LLM node. Restart ComfyUI afterwards; you'll find this one under JT > JT/text.

    The catch (it's minor)

    The pack's README is all in Chinese, and the author's "smart" digit adjustment means you can't force truncation - if you need fixed-width serials for a spec that demands exactly four characters, drive the input so the number never exceeds the width. That's not really a bug; it's just the node declining to be clever in a way that could lose data. For everything else, this is the rare utility node that does one thing, does it correctly, and doesn't try to be a Swiss army knife.

    CategoryJT/text

    Inputs (2)

    NameTypeDefaultDescription
    numberINT10–99999
    digitsINT41–5

    Outputs (1)

    NameTypeDescription
    STRINGSTRING