You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now the only way to normalize a path is by calling GetFullPath, but this is not always desirable. This could be especially useful since .NET is cross platform now. Thoughts?
GetFullPath would resolve a path relative to the root directory or working directory. I have multiple cases where I work with relative paths (working with archives and other stuff) where I want to print normalized paths (that are "full" paths in said archive, but not on the system).
/// <summary>/// Try and remove relative segments from the given path (without combining with a root)./// </summary>/// <param name="skip">Skip the specified number of characters before evaluating.</param>privatestaticstringRemoveRelativeSegments(stringpath,intskip=0){
What I was thinking was changing '/' and '' to DirectorySeparatorChar (e.g. '/' -> '' on windows). Didn't think about relative segments, but that could be useful to have too.
This method does that as well. It also collapses runs of directory separators. UNCs and extended paths on Windows are weird so it would need to be altered some to be public (don't want to collapse the first two separators \\).
Activity
JeremyKuhne commentedon Oct 29, 2015
@xPaw What specifically are you looking to avoid by not calling GetFullPath?
xPaw commentedon Oct 29, 2015
GetFullPath would resolve a path relative to the root directory or working directory. I have multiple cases where I work with relative paths (working with archives and other stuff) where I want to print normalized paths (that are "full" paths in said archive, but not on the system).
JeremyKuhne commentedon Oct 29, 2015
What you want is this, right?
https://github.com/dotnet/corefx/blob/master/src/System.Runtime.Extensions/src/System/IO/Path.cs#L426
xPaw commentedon Oct 29, 2015
What I was thinking was changing '/' and '' to
DirectorySeparatorChar(e.g. '/' -> '' on windows). Didn't think about relative segments, but that could be useful to have too.JeremyKuhne commentedon Oct 29, 2015
This method does that as well. It also collapses runs of directory separators. UNCs and extended paths on Windows are weird so it would need to be altered some to be public (don't want to collapse the first two separators
\\).xPaw commentedon Oct 29, 2015
Then yes, this method sounds reasonable.
wli3 commentedon Jun 26, 2018
@JeremyKuhne I have the same problem. And the previous solution is moved to internal at dotnet/corert#5520. Is there any alternative?
JeremyKuhne commentedon Jun 26, 2018
https://github.com/dotnet/corefx/blob/66110e6e5b0cdca7d212adb2062602ca4d041cfa/src/Common/src/CoreLib/System/IO/PathInternal.cs#L117
This is useful for a number of scenarios. Reopening so we can track.
@Anipik, this is the follow up I discussed with you. Can you help drive getting a formal API proposal together?
Anipik commentedon Jun 27, 2018
@JeremyKuhne I will write a formal Api proposal for it.
ahsonkhan commentedon May 11, 2019
Since https://github.com/dotnet/corefx/issues/30701 is targeting Future, moving this to Future as well.
JeremyKuhne commentedon Jan 14, 2020
Duplicate of #2162