Friday, September 26, 2014

Retrieving Directory Name or File Name using Powershell

# File should exist> (Get-Item 'C:\Windows\test.txt').DirectoryName
C:\Windows


> (Get-Item 'C:\Windows\test.txt').Name
test.txt


# File does not have to exist> Split-Path 'C:\Windows\test.txt'
C:\Windows


> Split-Path -Parent 'C:\Windows\test.txt'
C:\Windows


> Split-Path -Leaf 'C:\Windows\test.txt'
test.txt