Reputation: 20777
If I use a disk (not URL) path with ~
, e.g. ~/mike/foo
, then the runtime appends it to the current working directory instead of expanding it.
These don't work:
Path.GetFullPath
Path.Combine
Is there a built-in .NET Core function that would expand such a path safely, cross-platform?
Upvotes: 10
Views: 1495
Reputation: 20777
My cross-platform workaround:
myPath = myPath
.Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))
.Replace("//", "/");
But there are presumably edge cases (especially cross-platform), as always. So a built-in .NET Core function, if one exists, is preferable.
(Please add your answer and I'll accept it.)
Upvotes: 10