Getting the folder name

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

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>