ComfyUI Node

Build Path

Build a save path that's actually a folder, not a fire hazard

By luku756·Created about a month ago·Updated about a month ago· 0
Build Path
    • path
    segment_size4
    fix_invalid_charstrue
    segment_1
    segment_2
    segment_3
    segment_4
    segment_5
    segment_6
    segment_7
    segment_8
    segment_9
    segment_10

    If you generate images for more than a week, your output folder turns into a flat landfill. Build Path is StringKit's answer: it assembles a folder path out of up to ten segments, joins them with /, and - this is the good part - sanitizes every segment so the result is a path Windows won't reject and a folder you can actually find again. Type 2026-08-23/sunset/beach/smile as segments and out comes 2026-08-23/sunset/beach/smile, ready to feed a save node.

    What you set

    • segment_size - 1 to 10, how many segment boxes are visible. The extra boxes fold away, like the socket count on Join Texts.
    • fix_invalid_chars - on by default. This is the fire-prevention toggle, and it's the reason to use this node at all.
    • segment_1 … segment_N - the path pieces. You can type them directly or drag a link onto a segment. That last part is the workflow-saver: wire your Unpack Text title output straight into a segment and every image lands in a folder named after its prompt, no text node in between.

    With fix_invalid_chars on, each segment gets scrubbed: \ / : * ? " < > | and control characters become _ (so a title like smile:1.1 won't break the path), trailing dots and spaces are removed, and Windows-reserved names like CON, PRN, NUL, COM1LPT9 get a _ prefix so they don't silently vanish. Turn it off and a / inside a segment survives - one segment becomes several path levels, which is occasionally exactly what you want.

    Date tokens, done properly

    %year%, %month%, %day%, %hour%, %minute%, %second% are expanded by the node itself, and all segments use the same timestamp within a run, so a folder won't fracture across a midnight boundary. There's also an IS_CHANGED hook: the node returns the expanded path as its cache signature, so when the date rolls over it re-runs instead of serving you yesterday's cached folder. That's a subtle bug killer - without it, ComfyUI's aggressive caching would happily write today's images into yesterday's directory.

    One mismatch to know about: ComfyUI's own %date:yyyy-MM-dd% token is not supported here. That format is expanded by the frontend for widget values only, so it never fires on strings arriving via links. Use StringKit's %year% family instead.

    Install

    Ships in ComfyUI-StringKit - MIT, pure Python, no models or dependencies. ComfyUI Manager (search ComfyUI-StringKit) or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/luku756/ComfyUI-StringKit
    

    Restart ComfyUI completely afterward; the collapsing segments are frontend JS. Found under the StringKit category.

    Wire the path output into a save node's filename prefix and you get self-organizing folders: date on top, prompt title below. Filenames are cosmetic in ComfyUI - the workflow lives in the PNG - but folders you can navigate are not, and this is the rare string node that actually pays you back in sanity.

    CategoryStringKit

    Inputs (12)

    NameTypeDefaultDescription
    segment_sizeINT41–10
    fix_invalid_charsBOOLEANtrue
    segment_1STRING
    segment_2STRING
    segment_3STRING
    segment_4STRING
    segment_5STRING
    segment_6STRING
    segment_7STRING
    segment_8STRING
    segment_9STRING
    segment_10STRING

    Outputs (1)

    NameTypeDescription
    pathSTRING