PowerShell for Windows Admins

Apr 30 2013   2:09PM GMT

Getting the folder name

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Consider the file information from get-childitem

PS> $file = ls servicesv0.6.txt

Fullname gives the full path to the file

PS> $file.Fullname
C:\MyData\SkyDrive\Data\scripts\servicesv0.6.txt

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

PS> $file.DirectoryName
C:\MyData\SkyDrive\Data\scripts

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

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

However on a Windows 8/PS 3 setup you can also do this
PS> $file.Directory | select -ExpandProperty Name
scripts

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: