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(file, strict)
if nargin < 2
  strict = false;
end

[s, r] = fileAttribCompatible(file);

if s == 1
  c = r.Name;
elseif ~strict && ~stdlib.strempty(r)
  c = stdlib.normalize(file);
else
  c = '';
end

if isstring(file)
  c = string(c);
end

end

%!assert (length(stdlib.canonical('.')) > 1)