[英]Powershell/windows 10: how to count files inside a folder?
I think it's best described with an example 我认为最好用一个例子来描述
parent1 (located inside my documents)
- folder1
- test11.png
- test11.txt
- folder11
- test111.png
- folder12
- test121.png
- test122.png
- folder2
- test21.png
if I run the command/script supplying the path and the extension, the output should be: 如果我运行提供路径和扩展名的命令/脚本,则输出应为:
folder1: 4
folder2: 1
If I don't supply the extension, all files will be counted. 如果我不提供扩展名,则将计算所有文件。
Any ideas on how this can be done? 关于如何做到这一点的任何想法?
Thanks 谢谢
This can be done using Get-ChildItem
and Measure-Object
cmldets. 可以使用
Get-ChildItem
和Measure-Object
cmldets完成。
$RootDirectory = 'C:\Program Files (x86)'
Get-ChildItem $RootDirectory -Recurse -Directory |
ForEach-Object {
$DirectoryName = $_.FullName
$FilesCount = Get-ChildItem -Path $DirectoryName -File | Measure-Object | Select -ExpandProperty Count
'{0}: {1}' -f $DirectoryName, $FilesCount
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.