os.path.commonpath
Find the shared folder of a set of paths — os.path.commonpath
- paths
- path
Ovum Os Path CommonPath wraps Python's os.path.commonpath: give it a list of paths and it returns the longest common sub-path - the deepest directory that contains all of them. Feed it C:\renders\projectA\a.png, C:\renders\projectA\b.png, and C:\renders\projectA\sub\c.png, and you get C:\renders\projectA back. It's the "what's the shared root folder here?" node.
Where's that useful in a ComfyUI graph? When you're working with a batch of output files and need to derive the common output directory to pass to a saver, a folder-based image list loader, or a cleanup node. Or when you're grouping results - if several generated files live under one project folder, commonpath tells you the grouping in a single step. It's a genuine utility for path-driven workflows, even if it reads like a Python docs page title.
One warning up front: commonpath is segment-aware. It compares path components, not characters. That's the behavior you actually want for directories - and it's exactly why it's a different node from commonprefix in this same family, which compares character-by-character and can cheerfully return a half-typed folder name like C:\renders\project. If you want the real shared directory, this is the node.
How it works
Pure os.path.commonpath(paths) delegation. It resolves the input list, runs the stdlib function, and returns the shared directory as a string, with an optional forward_slashes normalization. No filesystem access - like all os.path string functions, it works purely on the path strings.
The inputs and outputs that matter
- paths (required, LIST) - the list of path strings to compare.
- forward_slashes (BOOLEAN, default false) - normalize separators in the result.
- path (output, STRING) - the longest common sub-path.
Installing it
Ships in comfy-ovum (sfinktah). Install via ComfyUI Manager - search "comfy-ovum" - or:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
Restart after. No models to download; the pack's dependencies are light and Manager handles them.
Common issues
The one that bites is platform mixing: on Windows, paths on different drives (or a mix of drive-letter and UNC paths) have no common path, and Python raises a ValueError - which surfaces as a node error rather than a graceful empty result. Keep your inputs on the same drive. Also note commonpath is case-sensitive on most systems, so C:\Renders and c:\renders won't share a path the way you'd expect. If a "shared root" result that includes the filename itself looks wrong, double-check you passed directories-within, not a single path.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| paths | LIST | — | |
| forward_slashesopt | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| path | STRING | — |