safe dirname