Fix unlinking directories referred to with trailing slashes

#3144