ROOT_DIR get root directory

Examples:

Contents

Windows

Unix

function r = root_dir(p)
arguments
  p string
end

r = repmat("", size(p));

i = startsWith(p, "/" | filesep);
r(i) = extractBefore(p(i), 2);

if ispc()
  i = startsWith(p, lettersPattern(1) + ":" + characterListPattern("/" + filesep));
  r(i) = extractBetween(p(i), 3, 3);
end

end