Categories

Folder and file names

Saw a question in the forums – running Get-ChildItem and wanted the folder containing the file.  Could split PSParent and pick the last element or can use a calculated field

Get-ChildItem -Path c:\test -Recurse |
select FullName, @{N="Folder"; E={Split-Path -Path (Split-Path -Path $_.fullname -Parent) -Leaf  }}

use split-path to get the container and put that into split-path to get the leaf i.e. the last folder in the path.

Jobs a good un!

Leave a Reply