If I use a disk (not URL) path with ~
, eg ~/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?
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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.