[*isfolder:ne=`1`:then=`<a href="[~[*parent*]~]">Back</a>`:else=``*]
would output the link on the last item which is not a folder.
But a snippet grabbing the parents and ultimate parent id can be used to calculate
this... Try google this, think it exists already.