Categories

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

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>