Skip to content

Make System.IO.Path.NormalizePath public #15584

Closed

Description

@xPaw

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?

Activity

  1. JeremyKuhne commented on Oct 29, 2015

    @JeremyKuhne
    Member

    @xPaw What specifically are you looking to avoid by not calling GetFullPath?

  2. xPaw commented on Oct 29, 2015

    @xPaw
    ContributorAuthor

    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).

  3. JeremyKuhne commented on Oct 29, 2015

    @JeremyKuhne
    Member

    What you want is this, right?

            /// <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>
            private static string RemoveRelativeSegments(string path, int skip = 0)
            {

    https://github.com/dotnet/corefx/blob/master/src/System.Runtime.Extensions/src/System/IO/Path.cs#L426

  4. xPaw commented on Oct 29, 2015

    @xPaw
    ContributorAuthor

    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.

  5. JeremyKuhne commented on Oct 29, 2015

    @JeremyKuhne
    Member

    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 \\).

  6. xPaw commented on Oct 29, 2015

    @xPaw
    ContributorAuthor

    Then yes, this method sounds reasonable.

  7. wli3 commented on Jun 26, 2018

    @wli3

    @JeremyKuhne I have the same problem. And the previous solution is moved to internal at dotnet/corert#5520. Is there any alternative?

  8. JeremyKuhne commented on Jun 26, 2018

    @JeremyKuhne
    Member

    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?

  9. Anipik commented on Jun 27, 2018

    @Anipik
    Contributor

    @JeremyKuhne I will write a formal Api proposal for it.

  10. ahsonkhan commented on May 11, 2019

    @ahsonkhan
    Contributor
  11. JeremyKuhne commented on Jan 14, 2020

    @JeremyKuhne
    Member

    Duplicate of #2162

  12. transferred this issue fromdotnet/corefxon Jan 31, 2020
  13. added this to the 5.0 milestone on Jan 31, 2020
  14. ghost locked as resolved and limited conversation to collaborators on Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-needs-workarea-System.IO

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions