STEM base file name without directory or suffix

s = stem(p) returns the stem (base name) of the file specified by the path p.
leading dot filenames are allowed.

Contents

Inputs:

Output:

Note: fileparts() was about 100x faster then using multiple steps with pattern.

function s = stem(filepath)

[~, s, e] = fileparts(filepath);

if stdlib.strempty(s)
  s = e;
end

end

%!assert (stdlib.stem('a/b.c'), 'b')