ComfyUI Node

normalize

Clean up messy paths without a regex in sight

By StableLlama·Created about a year ago·Updated 4 days ago· 48
normalize
    • normalized path
    path

    Basic data handling: PathNormalize ("normalize") takes a path that's a mess and makes it tidy. Redundant separators collapse, .. up-level references resolve, stray ./ segments disappear, and the separator style gets converted to your OS's native one. One path in, one cleaned path out.

    You'll want it whenever a path enters your workflow from somewhere you don't fully trust. PathGlob returns paths from the OS, so those are usually fine - but paths typed by hand, read from a config file via PathLoadStringFile, or assembled by joining pieces often come in dirty: ./input//photos/../photos/photo.png. That works by luck in some contexts and breaks in others. Run it through PathNormalize once and downstream nodes get a consistent, predictable path. It's the "sanitize your input" step that automation workflows tend to discover they needed.

    How it works

    It's a wrapper around Python's os.path.normpath(path). The important limits:

    • It's lexical, not physical. It resolves .. and collapses separators by string manipulation - it does not touch the disk, does not resolve symlinks, and does not make a relative path absolute. foo/../bar becomes bar, but the path can still point at nothing.
    • .. above the root is clipped. ../.. on an already-rooted path just stops at the root rather than going above it.
    • It can produce empty output. Normalizing "" gives "." - fine - but normalizing a path like foo/.. gives ".", and normalizing foo/../ gives "". Both are technically valid Python behavior and both will confuse you downstream if you feed them to a loader.

    Inputs and outputs

    • path (STRING, default "") - the path to normalize.
    • normalized path (STRING) - the cleaned result, using your OS's native separator.

    Installing it

    Part of Basic data handling, the no-dependency pack. ComfyUI Manager → search "Basic data handling" → install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart after. No models, no pip.

    Gotchas

    Two things keep tripping people up. First, it's not os.path.abspath - if you want the path resolved to absolute against the current working directory, that's this pack's separate abspath node (or chain PathGetCwd + PathJoin + PathNormalize). Normalize alone won't anchor a relative path. Second, the output can be "" for paths that reduce to nothing, and that empty string will fail in a loader or silently do nothing in a save. If your input is user-supplied, normalize then check PathExists - that combination catches both the empty-string case and the never-existed case. It's a quiet cleanup node, unglamorous, and exactly the kind of thing that saves a workflow from a whole family of weird failures.

    CategoryBasic/Path

    Inputs (1)

    NameTypeDefaultDescription
    pathSTRING

    Outputs (1)

    NameTypeDescription
    normalized pathSTRING