Skip to content

Add Levels/Count/AncestorCount to Split-Path -Parent parameter set #6659

Closed

Description

I quite often end up in situations where I need to remove a known number of directories from the end of a path.

Today, it requires a looping or piping multiple times to split-path.

$ancestorLevel = 4
$p = "a\b\c\d\e\f"
while($ancestorLevel--){
   $p = split-path $p
}
$p

What is the opinion around having the following?

Split-Path -Parent a\b\c\d\e\f -AncestorLevel 2
a\b\c\d

Split-Path -Parent a\b\c\d\e\f -AncestorLevel 4
a\b

Better naming is left as an exercise for attentive readers with English as their native toungue.

Activity

  1. iSazonov commented on Apr 15, 2018

    @iSazonov
    Collaborator

    We could solve this with #5270

  2. added
    Issue-Discussion
    on Apr 15, 2018
  3. powercode commented on Apr 15, 2018

    @powercode
    CollaboratorAuthor

    Yes, but with less precision since the path separators differ from system to system.
    Seems more error prone to me.

  4. iSazonov commented on Apr 16, 2018

    @iSazonov
    Collaborator

    Another question is maybe it is usefull enhancement for .Net API?

  5. BrucePay commented on Apr 17, 2018

    @BrucePay
    Collaborator

    Ilya (@iSazonov) Split-Path is specific to PowerShell in that it depends on the providers to split paths. This means that, along with file paths, it can split registry paths, AD paths, etc. So I don't think .NET will be interested in this specific scenario.

  6. iSazonov commented on Apr 18, 2018

    @iSazonov
    Collaborator

    Bruce Payette (@BrucePay) I don't understand why a script writer is interesting in the feature and C# writer is not. Also .Net has special class System.IO.Path which could be enhanced with the feature. For other providers we could do it in the repo.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  9. added
    Resolution-No Activity
    on Nov 16, 2023
  10. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  11. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-DiscussionResolution-No ActivityWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions