header image

Getting the folder name

Posted by: | April 30, 2013 | No Comment |

Consider the file information from get-childitem

PS> $file = ls servicesv0.6.txt


Fullname gives the full path to the file

PS> $file.Fullname


if you use DirectoryName you get the full path to the parent directory


PS> $file.DirectoryName


The easiest way to get the folder holding the path is like this

PS> Split-Path -Path $file.DirectoryName -Leaf


However on a Windows 8/PS 3 setup you can also do this

PS> $file.Directory | select -ExpandProperty Name

under: PowerShell original, Scripting Games