PowerShell Genie

Split-Path

Use Split-Path to return one part of a path: the parent directory, the file name, the extension, or the qualifier.

Command 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Split-Path

Syntax

1PS> Split-Path [-Path] <String[]> [-Parent | -Leaf | -LeafBase | -Extension | -Qualifier | -NoQualifier | -IsAbsolute] [-Resolve] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Split-Path [-Path] <String[]> [-Parent | -Leaf | -LeafBase | -Extension | -Qualifier | -NoQualifier | -IsAbsolute] [-Resolve] [<CommonParameters>]
  1. Stage 1Split-Path-Path -Parent
  2. Stage 2-Leaf-Leaf
  3. Stage 3-LeafBase-LeafBase
  4. Stage 4-Extension-Extension
  5. Stage 5-Qualifier-Qualifier
  6. Stage 6-NoQualifier-NoQualifier
  7. Stage 7-IsAbsolute]-IsAbsolute -Resolve

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    Split-Path -Parent

    1PS> Split-Path 'C:\Scripts\Backup-Files.ps1' -Parent
    Show reference output

    Sample output · fictional data, shaped like the real thing

    C:\Scripts

    Split-Path -Leaf

    1PS> Split-Path 'C:\Scripts\Backup-Files.ps1' -Leaf
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Backup-Files.ps1

    Split-Path -LeafBase

    1PS> Split-Path 'C:\Scripts\Backup-Files.ps1' -LeafBase
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Backup-Files

    Parameters

    Parameter definitions:

    • -Path
    • -Parent
    • -Resolve

    Split-Path on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Split-Path when you need to return one part of a path: the parent directory, the file name, the extension, or the qualifier. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: A leaf name being mistaken for a full path can send later commands to the wrong directory. Choose -Leaf or -Parent explicitly and keep the original path for subsequent file access. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Join-Path. Join-Path combines a parent with a child path using the provider; Split-Path extracts parts of a path. Neither command proves that a file exists. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Split-Path reference on Microsoft Learn

    Recap

    Split-Path Use Split-Path to return one part of a path: the parent directory, the file name, the extension, or the qualifier.

    Next: Test-Path
    Genie guideSplit-Path

    Use Split-Path to return one part of a path: the parent directory, the file name, the extension, or the qualifier. The console below is pre-loaded — run it, then change a value and run it again.