【发布时间】:2014-12-06 20:44:17
【问题描述】:
我有一个充满子目录的目录,其中包含任意数量的 0 到 300 个文件。
我要输出子目录名和子目录中的文件数
到目前为止,无论子目录中有多少实际文件,我都给我 0。
$dir = "C:\Folder\"
$subFiles = (Get-ChildItem $dir -recurse | where-object {$_.PSIsContainer -eq $true })
$subFiles | % {
Get-ChildItem -Path $_ -Force -Recurse | Measure-Object | Select-Object -ExpandProperty Count
write-host "$_"
}
它有时还包括运行脚本的目录,即“C:\Users\Blah\documents and settings\startmen”并导致错误。
非常感谢您的帮助
【问题讨论】:
标签: file powershell directory powershell-3.0 powershell-ise