This function previously wrote a trailing directory separator, but that's not correct if the path refers to a file.