relative
Get a path relative to another folder — or to your cwd
- relative path
Basic data handling: PathRelative ("relative") computes how to get from one path to another - the relative path between two locations, expressed without a full drive or root prefix. Give it a target path and an optional start folder, and it returns the ..\ and name hops that connect them. Leave start empty and it uses the current working directory.
Where does that matter in a ComfyUI workflow? The honest case is portability and logging. Absolute paths embed your machine's layout - C:\Users\You\projects\renders\frame_042.png - into whatever you record or pass along. A relative path like renders\frame_042.png (relative to a shared base) means the same workflow run on a different machine produces comparable, portable results. If you're building an automation that writes a manifest, a log, or a batch script describing what it processed, expressing those paths relative to a fixed base folder makes the output meaningful off your box. It's also the inverse of PathJoin: join builds up, relative tears down.
How it works
It calls Python's os.path.relpath(path, start). Mechanics worth knowing:
- Relative to what? If
startis provided, the result is relative to it. If empty, it defaults toos.getcwd()- so the output depends on how ComfyUI was launched, which is a moving target. Pass an explicitstart(likePathInputDir's output) whenever you want a stable answer. - It doesn't check existence. The math is pure string manipulation - both paths can be entirely imaginary and you'll still get a sensible-looking relative result. It also has the usual caveat that Windows paths are only comparable when both are absolute or both relative.
- It can emit
..hops. If the target isn't inside the start folder, you get..\..\other\file.pngstyle output. That's correct, just ugly, and exactly what a portable path looks like.
Inputs and outputs
- path (STRING, default
"") - the target path you want expressed relatively. - start (STRING, default
"", optional) - the base to make it relative to; defaults to cwd when empty. - relative path (STRING) - the result.
Installing it
Part of Basic data handling, zero dependencies. 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
The cwd default is the trap. Because start defaults to the working directory, two runs of the same graph can produce different relative paths if you launched ComfyUI from different folders - which makes the output look nondeterministic when it isn't. Always pass an explicit start for results you intend to compare or store. And remember it's pure arithmetic: no file needs to exist, and there's no normalization happening first, so feeding in ..-laden or mixed-separator paths gives you whatever the math produces. A niche node, but the right tool when portability of descriptions (not just files) is the goal.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| path | STRING | — | |
| startopt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| relative path | STRING | — |