Just now I have a path like this MyDir\Inner\Foo
and I want to be able to transform it into MyDir\Inner
.
My idea was to use Path.Combine(myRelativeDir, "..")
and then (for user display purposes) resolve it to remove the ..
.
When I've researched this online, I can only seem to find solutions that involve doing a Path.GetFullPath
after Path.Combine
to resolve it, but this does not help me as it results in something like C:\RootFolders\ThatIWantToHide\MyDir\Inner
and I don't want to show a full path.
Is there anything in the standard libraries that allows this or will I have to resort to string manipulation of some sort?
In summary
Input:
MyDir\Inner\Foo
(relative path)
Desired Output:
MyDir\Inner
(relative path maintained)
Undesired Output:
C:\RootFolders\ThatIWantToHide\MyDir\Inner
(relative path lost)
Undesired Output:
Inner
(just the name, not the relative path)