\documentclass{article}
\usepackage[T1]{fontenc}% for \texttt{->}
\makeatletter
\catcode`A 3 % create some improbable token as delimiter
% as we are using LaTeX for the demo, perhaps
% we should have used @nil
% switch utility
\long\def\uppera@switch #1A#2#3\uppera@switch{#2}
% we incorporate slight overhead to expand in exactly two steps
% also we avoid brace removal of last item in this variant
% (thanks to extending it by @nil and also by fetching two
% items at a time)
\long\def\afterlastslash#1{\romannumeral\afterlastslash@i#1@nil/A/}
\long\def\afterlastslash@i #1/#2/{%
% notice that brace removal can happen in intermediate #2 but this
% is not important, as the final "basename" is protected by the added @nil
\uppera@switch #2{\afterlastslash@clean@empty#1}A{\afterlastslash@i#2/}\uppera@switch
}
% @empty token will prevent brace removal in this last step
\long\def\afterlastslash@clean#1@nil{\expandafter\z@#1}
\catcode`A 11
\makeatother
% wipet https://tex.stackexchange.com/a/684771/293669
% \def\afterlastslash#1{\afterlsA#1/\end}
% \def\afterlsA#1/#2{\ifx#2\end #1\else \expandafter\afterlsA\expandafter#2\fi}
\begin{document}
\newcommand\test[1]{\texttt{\detokenize{\afterlastslash{#1}}} expands to \texttt{\afterlastslash{#1}}}
\test{/oof/bar} % expands to bar
\test{/{oof}/bar} % expands to bar
\test{{braced/path}/bar} % expands to bar
\test{{/path}/bar} % expands to bar
\test{/foo/bar/next} % expands to next
\newcommand\testedef[1]{\texttt{\detokenize{\edef\x{\afterlastslash{#1}}}} gives meaning
\edef\x{\afterlastslash{#1}}\texttt{\meaning\x<after meaning>}}
\testedef{/foo/bar/next}
\testedef{/foo/bar/next/}
Check that two expansions suffice
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\x
\expandafter\expandafter\expandafter{\afterlastslash{/foo/bar/next}}
\texttt{\meaning\x<after meaning>}
Check no brace removal regarding last item
\edef\x{\afterlastslash{/foo/bar/{last is kept braced}}}\texttt{\meaning\x<after meaning>}
\end{document}