Environment: Powershell 5.1 and Windows 10 Pro
Why is my list not sorting like showed in
CodePudding user response:
Easiest way to accomplish this would be to not use the -Name
switch on Get-ChildItem
:
Get-ChildItem -Path .\ -Filter *.baml -Recurse -File | Sort-Object Name |
Select-Object Name, DirectoryName
Above command would output objects, not strings, DirectoryName
would be the absolute path to the parent directory of each file.
As for why it's not currently sorting, after using the -Name
switch, the output is an array of strings, only the Name
property Value of the files is outputted hence sorting by the Name
property is no longer possible (Sort-Object Name
) since strings don't have a Name
a property.