windows 使用 Powershell 命令进行文件计数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8239905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
File counting with Powershell commands
提问by Elmex
How can I count all files in a specific folder (and all subfolders) with the Powershellcommand Get-ChildItem?
With (Get-ChildItem <Folder> -recurse).Count
also the folders are counted and this is not that what I want. Are there other possibilities for counting files in very big folders quickly?
如何使用Powershell命令 Get-ChildItem计算特定文件夹(和所有子文件夹)中的所有文件?随着(Get-ChildItem <Folder> -recurse).Count
也文件夹进行计数,这不正是我想要的。是否有其他可能性可以快速计算非常大的文件夹中的文件?
Does anybody know a short and good tutorial regarding the Windows Powerhell?
有人知道关于 Windows Powerhell 的简短而好的教程吗?
回答by Shay Levy
I would pipe the result to the Measure-Object
cmdlet. Using (...).Count can yield nothing in case there are no objects that match your criteria.
我会将结果通过管道传输到Measure-Object
cmdlet。如果没有符合您的条件的对象,则使用 (...).Count 不会产生任何结果。
$files = Get-ChildItem <Folder> -Recurse | Where-Object {!$_.PSIsContainer} | Measure-Object
$files.Count
In PowerShell v3 we can do the following to get files only:
在 PowerShell v3 中,我们可以执行以下操作来仅获取文件:
Get-ChildItem <Folder> -File -Recurse
回答by jon Z
Filter for files before counting:
计数前过滤文件:
(Get-ChildItem <Folder> -recurse | where-object {-not ($_.PSIsContainer)}).Count