【问题标题】:File counting with Powershell commands使用 Powershell 命令进行文件计数
【发布时间】:2011-11-23 09:35:22
【问题描述】:

如何使用 Powershell 命令 Get-ChildItem 计算特定文件夹(以及所有子文件夹)中的所有文件? 使用(Get-ChildItem <Folder> -recurse).Count,文件夹也被计算在内,这不是我想要的。还有其他方法可以快速计算非常大的文件夹中的文件吗?

有人知道有关 Windows Powerhell 的简短而好的教程吗?

【问题讨论】:

标签: windows powershell


【解决方案1】:

我会将结果传递给Measure-Object cmdlet。如果没有符合您的条件的对象,使用 (...).Count 不会产生任何结果。

 $files = Get-ChildItem <Folder> -Recurse | Where-Object {!$_.PSIsContainer} | Measure-Object
 $files.Count

在 PowerShell v3 中,我们可以执行以下操作来仅获取文件:

 Get-ChildItem <Folder> -File -Recurse

【讨论】:

    【解决方案2】:

    在计数之前过滤文件:

    (Get-ChildItem <Folder> -recurse | where-object {-not ($_.PSIsContainer)}).Count
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-27
      • 2015-05-25
      • 1970-01-01
      • 2013-05-01
      • 2018-08-25
      • 1970-01-01
      • 2020-02-04
      • 1970-01-01
      相关资源
      最近更新 更多