Perhaps use URIUtils::GetParentPath() instead in this case?

I *think* that URIUtils::GetDirectory() and that are equivalent in the else case as well?  Please review the code and see if you can see any cases where they're not.