Nodes/comfy-ovum/os.path.normpath
ComfyUI Node

os.path.normpath

The path-cleaner that fixes 'a//b/../c' nonsense

By sfinktah·Created about a year ago·Updated 10 months ago· 7
os.path.normpath
  • path_in
  • path
path
forward_slashesfalse

Hand a path to ComfyUI's path handling and it usually works - until the path comes from somewhere sloppy: a user's typed input with double slashes, a widget with a stray ./, a filename built by concatenation that ends in folder/../file. Those paths work, mostly, but they're fragile and they'll break string comparisons and dedup logic. os.path.normpath is the cleaner: it collapses //, resolves . and .. (lexically, without touching the filesystem), and hands back a tidy canonical form.

It's from the ovum/path/os.path family in comfy-ovum, a faithful wrapper over Python's os.path.normpath().

How it works

Takes a path, normalizes it purely as a string operation, returns a STRING (path). Inputs:

  • path (STRING, required): the widget.
  • forward_slashes (BOOLEAN, required, default false): convert backslashes to forward slashes in the output.
  • path_in (PATHLIKE,STRING, optional): link-only; overrides the widget when connected.

One STRING out.

Concretely: models//sd15/./v1/../v2.safetensors becomes models/sd15/v2.safetensors. It collapses repeated separators, eats ., and resolves .. by walking up a level - all without touching disk. It does not make a relative path absolute, and it does not resolve symlinks; those are abspath and realpath's jobs.

Where you'd use it

Run every externally-sourced path through normpath as soon as it enters your graph. That covers:

  • User-entered paths in widgets, where C:\models\ and C:\models and C:\models\..\models should all become the same clean string.
  • The output of os.path.join when any component might contain sloppy separators - join glues, normpath cleans.
  • Comparison and dedup. Two strings that normalize to the same path are the same path; two that don't, aren't. This is the prerequisite for meaningful path equality checks, alongside normcase if casing matters on your platform.

The forward_slashes toggle matters more here than on most siblings: normpath on Windows returns \-separated output, and if you're handing paths to something that wants / - Python code, URLs, a container - the toggle flips the whole chain in one click.

Installing it

Standard, once per pack:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Or ComfyUI Manager → "comfy-ovum" → Install → restart. No models, no extra deps.

Gotchas

  • Lexical, not physical. a/../b resolves to b even if a doesn't exist. That's usually what you want for cleanup, but it means normpath can hide the fact that a path was nonsense. It also won't resolve .. past the root - ../.. at the top of a path stays put.
  • Don't confuse it with realpath. realpath resolves symlinks and requires the path to exist; normpath is pure text surgery and works on anything. Different tools.
  • It changes nothing about the file's existence. Normalizing a missing path just produces a tidier missing path.

If you've ever debugged "these two paths are identical, why does the workflow treat them differently," the answer was probably missing normalization. One normpath at the front of your pipeline retires that whole bug class.

Categoryovum/path/os.path

Inputs (3)

NameTypeDefaultDescription
pathSTRING
forward_slashesBOOLEANfalse
path_inoptPATHLIKE,STRING

Outputs (1)

NameTypeDescription
pathSTRING