Get file path and file name from full file name

15/10/2012 15:32

$path = "c:\temp\filename.txt"

split-path $path

returns "c:\temp"

 

split-path $path -leaf

returns filename.txt

 

Get-Item $path | select BaseName, Extension

BaseName Extension

--------           ---------

bla                 .xml

 

If you want only e. g. Extension, use -ExpandProperty switch

 

Get-Item c:\temp\bla.xml | select -Expandproperty Extension

.xml