Path cmdlets: 2 Split-Path

Lets start with a file we now exists

PS> Test-Path -Path c:\scripts\utils\accelerators.ps1
True

By default we get the container when we use split-path

PS> Split-Path -Path c:\scripts\utils\accelerators.ps1
c:\scripts\utils

This is equivalent of

PS> Split-Path -Path c:\scripts\utils\accelerators.ps1 -Parent
c:\scripts\utils

If we want the file

PS> Split-Path -Path c:\scripts\utils\accelerators.ps1 -Leaf
accelerators.ps1

We can remove the drive

PS> Split-Path -Path c:\scripts\utils\accelerators.ps1 -NoQualifier
\scripts\utils\accelerators.ps1

or just get the drive

PS> Split-Path -Path c:\scripts\utils\accelerators.ps1 -Qualifier
c:

If we use wildcards

PS> Split-Path -Path c:\scripts\utils\*.ps1 -Leaf
*.ps1

In this case use the –resolve parameter

PS> Split-Path -Path c:\scripts\utils\*.ps1 -Leaf -Resolve
accelerators.ps1
font.ps1
get-assembly.ps1
Get-BingPowerShell.ps1

etc

Leave a Reply