os.path.relpath
'how do I get from here to there?' as a string
- path_in
- start_in
- path
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,
relpathis 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:
relpathbetween paths on different drives (C:\...toD:\...) raises aValueErrorbecause there's no relative route across drives. Same withstarton 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
startis the working directory, which in ComfyUI isn't always obvious. If you want deterministic output, always pass an explicitstart- 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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| path | STRING | — | |
| forward_slashes | BOOLEAN | false | — |
| path_inopt | PATHLIKE,STRING | — | |
| startopt | STRING | — | |
| start_inopt | PATHLIKE,STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| path | STRING | — |