I don't know what the purpose of this function is, but it's worth noting that the behavior differs if the path ends in a slash or not.