RosettaCodeData/Task/Find-common-directory-path/Liberty-BASIC/find-common-directory-path....

26 lines
710 B
Plaintext

path$(1) = "/home/user1/tmp/coverage/test"
path$(2) = "/home/user1/tmp/covert/operator"
path$(3) = "/home/user1/tmp/coven/members"
print samepath$(3,"/")
end
function samepath$(paths,sep$)
d = 1 'directory depth
n = 2 'path$(number)
while 1
if word$(path$(1),d,sep$) <> word$(path$(n),d,sep$) or word$(path$(1),d,sep$) = "" then exit while
n = n + 1
if n > paths then
if right$(samepath$,1) <> sep$ and d<>1 then
samepath$ = samepath$ + sep$ + word$(path$(1),d,sep$)
else
samepath$ = samepath$ + word$(path$(1),d,sep$)
end if
n = 2
d = d + 1
end if
wend
end function