NATIVE.RELATIVE_TO find relative path to target from base
function rel = relative_to(base, target)
arguments
base (1,1) string
target (1,1) string
end
if stdlib.strempty(base) || stdlib.strempty(target)
rel = "";
return
end
tp = strsplit(fullfile(target), filesep);
bp = strsplit(fullfile(base), filesep);
n = 0;
while n < length(tp) && n < length(bp) && strcmp(tp{n+1}, bp{n+1})
n = n + 1;
end
numUp = length(bp) - n;
relParts = [repmat({'..'}, 1, numUp), tp(n+1:end)];
if isempty(relParts)
rel = '.';
else
rel = fullfile(relParts{:});
if isempty(rel)
rel = '.';
end
end
rel = string(rel);
end