Monthly Archive

Categories

Paths: II

Two related cmdlets deal with paths – split-path and join-path.

Starting with split-path we can use it to split the path to retrieve the file or directory

PS> Split-Path -Path C:\Scripts\DC02\Scripts\DNS\new-mx.ps1
C:\Scripts\DC02\Scripts\DNS

PS> Split-Path -Path C:\Scripts\DC02\Scripts\DNS\new-mx.ps1 -Parent
C:\Scripts\DC02\Scripts\DNS

PS> Split-Path -Path C:\Scripts\DC02\Scripts\DNS\new-mx.ps1 -Leaf
new-mx.ps1

The default gives the parent container.

We can also separate the drive

PS> Split-Path -Path C:\Scripts\DC02\Scripts\DNS\new-mx.ps1 -Qualifier
C:

PS> Split-Path -Path C:\Scripts\DC02\Scripts\DNS\new-mx.ps1 -NoQualifier
\Scripts\DC02\Scripts\DNS\new-mx.ps1

 

join-path does the opposite

PS> Join-Path -Path C:\Scripts\DC02\Scripts\DNS -ChildPath new-mx.ps1
C:\Scripts\DC02\Scripts\DNS\new-mx.ps1

Useful for when you are building file paths

Technorati Tags: PowerShell,paths

Leave a Reply