os.path.commonprefix
Os.path.commonprefix — the naive sibling that finds shared characters
- list
- prefix
Ovum Os Path CommonPrefix wraps os.path.commonprefix, and the first thing you should know is that it is not commonpath. This node returns the longest string that is a prefix of every path in the list, compared character by character - not folder segment by folder segment. For C:\renders\a\1.png and C:\renders\ab\2.png it will happily return C:\renders\a, which is not a real directory. That's Python's documented behavior, faithfully reproduced.
So when do you actually want that? Rename operations, mostly. If you're stripping a common text prefix from a batch of filenames, or computing how much of a string is shared before building new names, character-level matching is exactly right. It's also handy for finding a shared file prefix (say AnimateDiff_) across generated outputs, where commonpath's segment logic would be the wrong tool. Just don't reach for it when you mean "shared folder" - that's OvumOsPathCommonPath, one node over in the same pack.
How it works
Delegation again: the node takes the input list and calls os.path.commonprefix(list) directly. No filesystem access, no normalization, no separator awareness beyond the raw characters. The output is whatever string is common to all inputs, which may end mid-filename or even mid-folder-name. There's no forward_slashes toggle on this one - it returns the prefix exactly as computed.
The inputs and outputs that matter
- list (required, LIST) - the list of path strings to compare.
- prefix (output, STRING) - the longest common character prefix.
Installing it
Part of comfy-ovum (sfinktah). ComfyUI Manager: search "comfy-ovum", install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
Restart after cloning. No models, no heavy dependencies - the pack's requirements are light and Manager installs them.
Common issues
The character-vs-segment trap above is the whole failure story. People wire this into folder logic, get a truncated path back, and assume the node is broken - it isn't, it's just the naive algorithm. A second gotcha: with a single path in the list, the "common prefix" is the whole path, which is rarely what you want; and with an empty list it returns an empty string. If you want the shared directory, switch to commonpath. If you want shared folder names without partial segments, that's the one.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| list | LIST | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| prefix | STRING | — |