powershell和windows资源管理器(属性)具有不同的计数结果



我正在递归地计算要检查文件夹与其AmazonS3备份的对象(文件、文件夹等(的总数
当我在文件夹上使用windows资源管理器(右键单击-->属性(时,我得到的对象总数少于以下powershell代码生成的对象总数。为什么
Amazon S3 100%匹配Windows资源管理器中的计数。为什么powershell给出了更高的总数,可能的区别是什么(系统文件、隐藏文件等(?这些文件夹中的对象总数通常为77000+。

folder_name; Get-ChildItem -Recurse | Measure-Object | %{$_.count}

要计算单独变量中的文件和文件夹数量,可以执行

# create two variables for the count
[int64]$totalFolders, [int64]$totalFiles = 0
# loop over the folders in the path
Get-ChildItem -Path 'ThePath' -Recurse -Force -ErrorAction SilentlyContinue | ForEach-Object {
if ($_.PSIsContainer) { $totalFolders++ } else { $totalFiles++ }
}
# output the results
"Folders: $totalFolders`r`nFiles: $totalFiles"

-Force开关可确保隐藏文件和系统文件也被计数。

一个可能更快的替代方案是使用自动复制:

$roboCount    = robocopy 'ThePath' 'NoDestination' /L /E /BYTES
$totalFolders = @($roboCount -match 'New Dir').Count - 1   # the rootfolder is also counted
$totalFiles   = @($roboCount -match 'New File').Count
# output the results
"Folders: $totalFolders`r`nFiles: $totalFiles"

我无法复制。

在文件资源管理器中,右键单击有问题的文件夹->特性在General选项卡下,有一个名为Contains的部分。这会将"文件"one_answers"文件夹"作为单独的编号列出。在我的例子中,我有19,267 Files, 1,163 Folders,它总共是20430个对象

当我运行时

Get-ChildItem -Path C:folder -Recurse | measure | % Count

返回20430

当我运行时

Get-ChildItem -Path C:folder -Recurse | ?{$_.PSiscontainer -eq $false} | measure | % count

返回19267

当我运行时

Get-ChildItem -Path C:folder -Recurse | ?{$_.PSiscontainer -eq $true} | measure | % count

返回1163

您确定在手动查看属性时同时计算文件和文件夹吗?

差异来自Windows资源管理器对文件和文件夹的计数。Powershell(版本2.0 Build 6.1(正在计算所有内容。似乎-File和-Directory在PowerShell V2.0中不起作用。

我真的希望能够以.cvs或.txt输出的形式从大量文件夹中(递归地(获得一个列表。浏览windows资源管理器是一个接一个的,我无法将其作为可以复制/粘贴的输出。