CANONICAL Canonicalize path

c = canonical(p); If exists, canonical absolute path is returned. if any component of path does not exist, normalized relative path is returned. UNC paths are not canonicalized.

This also resolves Windows short paths to long paths.

Contents

Inputs

Outputs

function c = canonical(p, strict, backend)
arguments
  p string
  strict (1,1) logical = false
  backend (1,:) string = ["native", "legacy"]
end

[fun, b] = hbackend(backend, "canonical", 'R2024a');

if isscalar(p) || b == "native"
  c = fun(p, strict);
else
  c = arrayfun(fun, p, repmat(strict, size(p)));
end

end