Reputation: 1503
I have two paths:
a = '/folder1/subfolder/'
b = '/subfolder/folder2'
How to combine them into
c = '/folder1/subfolder/folder2/'
in the simplest way?
Upvotes: 0
Views: 58
Reputation: 149736
Checking only the last component of a
, you could do:
A = a.strip('/').split('/')
B = b.strip('/').split('/')
if A[-1] == B[0]:
print("/{}/".format("/".join(A + B[1:])))
Upvotes: 1