按大小对所有文件夹中的所有文件进行排序

Han*_*ood 4 powershell

使用 PowerShell,如何按大小对所有文件夹中的所有文件进行排序?每当我使用 Get-ChildItem 的结果时,即使将其保存到变量并进行修改,它也会按目录对所有文件进行分组。即使这样,文件也不会在每个目录中排序。

$files = Get-ChildItem -File -Filter *.bat -Path C:\git -Recurse
Sort-Object -InputObject $files -Property Length
Run Code Online (Sandbox Code Playgroud)

Bac*_*its 6

我猜您正在运行 的默认显示模式System.IO.FileInfo,该模式会在更改时显示空行和目录名称。Mode由于该列的优化特别差,因此也需要很长时间才能显示。

尝试这样的事情:

Get-ChildItem -File -Filter *.bat -Path C:\git -Recurse |
    Sort-Object -Property Length |
    Select-Object -Property Length, Name |
    Format-Table -AutoSize
Run Code Online (Sandbox Code Playgroud)