common prefix
Finding what two paths share
- common prefix
Given two paths, what's the part they have in common? The common prefix node from Basic data handling answers that: feed it /home/you/ComfyUI/models/loras and /home/you/ComfyUI/models/checkpoints, and it returns /home/you/ComfyUI/models - the shared leading component.
In practice this is how you detect "are these two files in the same tree?" or "what's the common root these paths branch from?" before doing something conditional on the answer. It's a quiet utility, but it's one of those "ah, that's the node" discoveries when you need it.
How it works
A wrapper around Python's os.path.commonprefix(). The inputs:
path1- STRING, required (default empty).path2- STRING, optional (default empty).
Output is a single STRING named common prefix. Empty inputs are filtered out before comparing, so a single non-empty path just returns itself.
The gotcha that matters: it's character-based, not folder-based
This is the one you need to remember. os.path.commonprefix compares character by character, not folder by folder. It returns the longest string both paths share as text - which is usually, but not always, a whole folder boundary. The classic trap:
commonprefix("/home/you/models/lora", "/home/you/models/lion")→/home/you/models/l- because both strings literally share the letterl, and the function doesn't know (or care) that it's cut mid-folder-name.
If you need folder-level granularity ("the common directory", not the common characters), you'd be better off splitting on the separator first. For whole-directory comparisons this node is fine; just don't expect it to be path-aware beyond raw characters.
Also worth noting: comparison is case-sensitive, so /Home/you and /home/you share nothing past the first slash on a case-sensitive filesystem. And it's limited to two paths (path1, path2) - no ten-path variant here, even though the README's category mentions "multiple paths" in passing.
Where you'd use it
- Grouping - check whether two model paths live under the same directory before applying shared logic.
- Validating - confirm a file path is inside an expected root before passing it to a save/load node.
- Building folder chains - reconstruct a shared directory from two known paths.
Installing it
Basic data handling is dependency-free with no models to download. ComfyUI Manager, search "Basic data handling", install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart, and common prefix is under Basic/Path.
The take
Useful, but read the char-vs-folder caveat before you trust it for logic where the result must be a valid directory. Know the limitation and it's a handy little tool; ignore it and it'll hand you a half-folder name with a straight face.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| path1 | STRING | — | |
| path2opt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| common prefix | STRING | — |