Nodes/ComfyUI-LoadFiles/Line Count STRING
ComfyUI Node

Line Count STRING

CountLines (Line Count STRING) — ComfyUI node guide

By daryltucker·Created 2 years ago·Updated 2 years ago· 3
Line Count STRING
    • INT
    • FLOAT
    • STRING
    STRING

    CountLines does exactly what the name says: you hand it a string, and it counts the lines. That's the whole node. Sounds almost too small to bother writing about - but in ComfyUI, "how many things are in this list" turns out to be a number you need constantly, and there's no clean native way to get it. So this little counter earns its slot in a batch workflow.

    The reason it exists is its sibling. ListFilenames, from the same ComfyUI-LoadFiles pack, reads a folder and spits out the filenames as one newline-separated string. That string is a list, but ComfyUI sees it as text - it doesn't know it's "50 files." CountLines is the bridge: feed it that block of filenames and it tells you there are 50. Now you can set a batch count to 50, bound a loop index at 50, or gate a downstream branch on whether the folder was empty. ListFilenames says what's there, CountLines says how much.

    How it works

    It splits the incoming string on newlines and counts the pieces. Newline-delimited is the convention every list-producing node in this pack uses, so a string of filenames, a string of prompts, a wildcard list - anything one-item-per-line - counts correctly. It's not parsing files or touching disk; it's pure string math on whatever text you wire in. That makes it fast and side-effect-free, the kind of node you can drop anywhere without worrying it'll slow a run down.

    Inputs and outputs

    There's exactly one input and it's not optional:

    • STRING - the text to count lines in. In practice this is the STRING output of ListFilenames, but it'll count any multiline string you give it, so it works fine downstream of any node that emits a newline-separated list.

    The interesting part is the outputs - the same count, handed back in three different types:

    • INT - the count as an integer. This is the one you want 90% of the time: wire it into a batch-count widget, a loop bound, an index range, anything that expects a whole number.
    • FLOAT - the same count as a float. Some math and interpolation nodes only accept FLOAT sockets, and ComfyUI won't silently convert an INT for you, so having the float ready saves you a cast node in the middle of your graph.
    • STRING - the count as text, for when you want to show it - bake it into a filename, drop it in a label, concatenate it into a status line.

    Emitting the number three ways looks redundant until you're mid-graph and the socket you're trying to reach is the one type you don't have. It's a small quality-of-life call that means you never stall on a type mismatch. Wire whichever one your downstream node speaks.

    Installing it

    CountLines ships inside the ComfyUI-LoadFiles pack - you don't install it on its own, you install the pack and get both nodes.

    • ComfyUI Manager: search ComfyUI-LoadFiles, install, restart ComfyUI, refresh the browser.
    • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/daryltucker/ComfyUI-LoadFiles, then restart.

    No models, no chunky dependencies - it's a lightweight pure-Python pack, so it won't drag torch or transformers versions into your environment and start a dependency fight. Given how many custom-node install headaches trace back to exactly that, a utility pack that stays out of the way is a feature, not a footnote.

    Where it can trip you up

    Mostly it just works, but two things to keep in mind.

    Trailing newlines. If the input string ends with a blank line, some line-counting logic counts that empty line as one more entry. If your count comes back one higher than the number of files you can see, a trailing newline is the usual suspect. Peek at the raw string in a text-display node to confirm.

    Empty in, zero out. Point ListFilenames at a folder that doesn't match your regex and you get an empty string, and CountLines will happily report a very small number. That's not a bug - it's telling you the truth about an empty result. If a batch that should have run over a folder does nothing, check the count first; a zero here usually means the problem is upstream in your directory or limiter pattern, not in the loop itself.

    And the standard custom-node reminder: if the node doesn't show up after installing, you didn't fully restart. ComfyUI registers custom nodes at startup, so kill the process, start it again, and hard-refresh the tab.

    CategoryLoadFiles

    Inputs (1)

    NameTypeDefaultDescription
    STRINGSTRING

    Outputs (3)

    NameTypeDescription
    INTINT
    FLOATFLOAT
    STRINGSTRING