remove last trailing slash if exists

original php function works with path with trailing slash at the end too.