22 lines
729 B
Text
22 lines
729 B
Text
function common_directory_path(sequence paths, integer sep='/')
|
|
sequence res = {}
|
|
if length(paths) then
|
|
res = split(paths[1],sep)[1..-2]
|
|
for i=2 to length(paths) do
|
|
sequence pi = split(paths[i],sep)[1..-2]
|
|
for j=1 to length(res) do
|
|
if j>length(pi) or res[j]!=pi[j] then
|
|
res = res[1..j-1]
|
|
exit
|
|
end if
|
|
end for
|
|
if length(res)=0 then exit end if
|
|
end for
|
|
end if
|
|
return join(res,sep)
|
|
end function
|
|
|
|
constant test = {"/home/user1/tmp/coverage/test",
|
|
"/home/user1/tmp/covert/operator",
|
|
"/home/user1/tmp/coven/members"}
|
|
?common_directory_path(test)
|