简体   繁体   English

Powershell 以表格形式获取子文件夹列表和每个文件的数量

[英]Powershell get list of sub folders and number of files in each in a table format

I'd like to create a table showing the number of files in all subfolders named "andre tegninger" I've found the following code on here which I modified to filter by the sub folder I am interested in.我想创建一个表格,显示所有名为“andre tegninger”的子文件夹中的文件数量我在这里找到了以下代码,我对其进行了修改以按我感兴趣的子文件夹进行过滤。

dir -filter "*Andre tegninger*" -recurse |  ?{ $_.PSIsContainer } | %{ Write-Host $_.FullName (dir $_.FullName | Measure-Object).Count }

This works fine but is there a way I can get name of folder and number of files in two separate columns?这工作正常,但有没有办法我可以在两个单独的列中获取文件夹名称和文件数量? Thank you!谢谢!

You can use Select-Object to get in separate fields the expected properties:您可以使用Select-Object在单独的字段中获取预期属性:

dir -filter "*Andre tegninger*" -recurse | ?{ $_.PSIsContainer } | Select-Object -Property FullName, {(dir $_.FullName | Measure-Object).Count}

Since -Property expect a property (obviously) You have to use {} around (dir $_.FullName | Measure-Object).Count to tell powershell it's a calculated expression.由于 -Property 需要一个属性(显然),您必须在(dir $_.FullName | Measure-Object).Count周围使用{}来告诉 powershell 这是一个计算表达式。

You're getting as output:你得到的是 output:

FullName      (dir $_.FullName | Measure-Object).Count
--------      --------------------------------------
Your list of folders...

You can label the fields names to get them some fancy names, such as:您可以 label 字段名称为它们获取一些花哨的名称,例如:

dir -filter "*Andre tegninger*" -recurse | ?{ $_.PSIsContainer } | Select-Object -Property @{label="Path";expression={$_.FullName}}, @{label="Numer of files";expression={(dir $_.FullName | Measure-Object).Count}}

And you get as output:你会得到 output:

Path     Numer of files
----     --------------

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM