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

os.path.relpath

'how do I get from here to there?' as a string

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

Absolute paths are the safe default, but they're also the thing that makes a workflow non-portable: hand a graph with C:\Users\alice\models\... baked in to someone else and it's useless on their machine. Relative paths - ..\..\models\v1.safetensors - travel better, but nobody wants to hand-compute them. os.path.relpath computes the "get from here to there" string for you, given a target path and an optional starting point.

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

How it works

Given a target and (optionally) a start, it computes the relative route and returns it as a STRING (path). Inputs:

  • path (STRING, required): the target path you want the relative form of.
  • start (STRING, optional): the reference point. If blank, it defaults to the current working directory.
  • path_in, start_in (PATHLIKE,STRING, optional): link-only jacks that override the corresponding widgets.
  • forward_slashes (BOOLEAN, required, default false): convert backslashes to forward slashes in the output.

One STRING out. So path = /data/project/renders/out.png with start = /data/project gives you renders/out.png; flip the target and start around and you get ../data/project/renders/out.png style output.

Where you'd use it

  • Portable workflows. Build a base directory from a widget (or a Folder Paths node), compute relative paths for everything downstream, and sharing the workflow stops leaking your absolute filesystem layout.
  • Relative output names. If your saver accepts relative paths and resolves them against ComfyUI's output dir, relpath is how you convert an absolute path you received into the relative form it wants.
  • Logging and summaries. Relative paths are friendlier in a printed caption or a metadata string than a 90-character absolute path. Feed the output into the pack's Python String Format node and it slots right into a human-readable message.

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

  • It touches disk only if the path doesn't exist - the stdlib walks up looking for a common ancestor and can hit filesystem calls when things are missing. For well-formed existing paths it's fast and clean.
  • Windows gotcha: relpath between paths on different drives (C:\... to D:\...) raises a ValueError because there's no relative route across drives. Same with start on a different drive. If your workflow mixes drive letters, either catch that upstream or accept that relative paths across drives are a dead end on Windows.
  • Relative paths are only as good as their anchor. The default start is the working directory, which in ComfyUI isn't always obvious. If you want deterministic output, always pass an explicit start - usually your project root.

If you've ever shipped a workflow and watched the recipient rebuild every absolute path by hand, this node is the antidote. Pair it with os.path.join and you can construct fully portable, self-contained path logic.

Categoryovum/path/os.path

Inputs (5)

NameTypeDefaultDescription
pathSTRING
forward_slashesBOOLEANfalse
path_inoptPATHLIKE,STRING
startoptSTRING
start_inoptPATHLIKE,STRING

Outputs (1)

NameTypeDescription
pathSTRING