EXISTS does path exist

NOTE: in general on Windows exists("./not-exist/..") is true, but on Unix it is false. In C/C++ access() or stat() the same behavior is observed Windows vs Unix.

Contents

Inputs

Outputs

function y = exists(p)
arguments
  p (1,1) string
end

% Matlab >= R2024b allowed URLs to act like files or folders.
% fileattrib() does not consider URLs to be a file or folder
% at least through Matlab R2025a.

y = stdlib.len(p) && fileattrib(p) == 1;

end

%!assert (!exists(''))
%!assert (!exists(tempname))
%!assert (exists(program_invocation_name))