![](/img/trans.png)
[英]Powershell get list of all folders and files modified in the last 4 months in ascending order
[英]Powershell get list of sub folders and number of files in each in a table format
我想創建一個表格,顯示所有名為“andre tegninger”的子文件夾中的文件數量我在這里找到了以下代碼,我對其進行了修改以按我感興趣的子文件夾進行過濾。
dir -filter "*Andre tegninger*" -recurse | ?{ $_.PSIsContainer } | %{ Write-Host $_.FullName (dir $_.FullName | Measure-Object).Count }
這工作正常,但有沒有辦法我可以在兩個單獨的列中獲取文件夾名稱和文件數量? 謝謝!
您可以使用Select-Object
在單獨的字段中獲取預期屬性:
dir -filter "*Andre tegninger*" -recurse | ?{ $_.PSIsContainer } | Select-Object -Property FullName, {(dir $_.FullName | Measure-Object).Count}
由於 -Property 需要一個屬性(顯然),您必須在(dir $_.FullName | Measure-Object).Count
周圍使用{}
來告訴 powershell 這是一個計算表達式。
你得到的是 output:
FullName (dir $_.FullName | Measure-Object).Count
-------- --------------------------------------
Your list of folders...
您可以 label 字段名稱為它們獲取一些花哨的名稱,例如:
dir -filter "*Andre tegninger*" -recurse | ?{ $_.PSIsContainer } | Select-Object -Property @{label="Path";expression={$_.FullName}}, @{label="Numer of files";expression={(dir $_.FullName | Measure-Object).Count}}
你會得到 output:
Path Numer of files
---- --------------
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.