What's the opposite of os.path.commonprefix? I have two paths and I want the non-overlapping path, e.g.:
>>> p1 = '/Users/foo/something'
>>> p2 = '/Users/foo/something/else/etc'
>>> print somefunction([p1, p2])
'/else/etc'
>>> p1 = '/Users/foo/something'
>>> p2 = '/Users/foo/something/else/etc'
>>> os.path.relpath(p2, start=p1)
'else/etc'
The correct answer is 'else/etc'
and not '/else/etc'
.
If you are in p1 and type cd /else/etc
you wouldn't land in p2, but somewhere else.
os.path.join(p1, 'else/etc')
gives you p2 again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With