Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 计算目录下的文件数(包括子目录下的文件)_Windows_Powershell_Powershell 3.0 - Fatal编程技术网

Windows 计算目录下的文件数(包括子目录下的文件)

Windows 计算目录下的文件数(包括子目录下的文件),windows,powershell,powershell-3.0,Windows,Powershell,Powershell 3.0,我正在尝试查找公司共享驱动器上存在的目录下的文件总数。但是我没有权限访问几个子目录中的一些文件夹(严格限制)。我正在使用Windows PowerShell,但出现了许多错误,如,权限被拒绝,以及无法访问的文件夹路径。下面是我使用的命令 Get-ChildItem -Recurse | Measure-Object | %{$_.Count} 我的问题是,是否有一种方法可以找到所有目录和子目录中的文件总数,而忽略导致错误的受限文件?Powershell 3.0及更高版本: (Get-Child

我正在尝试查找公司共享驱动器上存在的目录下的文件总数。但是我没有权限访问几个子目录中的一些文件夹(严格限制)。我正在使用Windows PowerShell,但出现了许多错误,如,权限被拒绝,以及无法访问的文件夹路径。下面是我使用的命令

Get-ChildItem -Recurse | Measure-Object | %{$_.Count}

我的问题是,是否有一种方法可以找到所有目录和子目录中的文件总数,而忽略导致错误的受限文件?Powershell 3.0及更高版本:

(Get-Childitem -Recurse -path x:\whatever -erroraction SilentlyContinue | where {-not ($_.PSIsContainer)}).count
您可能仍然会看到错误,但您会得到一个答案

  (gci -Path C:\temp -File -Recurse -ErrorAction SilentlyContinue).Count
让我试试:

Get-Childitem "C:\Users" -File -Recurse -ErrorAction SilentlyContinue |
    Measure-Object |
    Select-Object -ExpandProperty Count

我认为这并不是在计算可访问文件夹中的所有文件。它向我展示了一个非常小的数字这是PS2多于PS3?但是结果是准确的。PS2不支持自动注册,我们在这里使用的是。请验证您没有更多的文件。没有将计数作为输出,而是将文件列在两个目录中,仅此而已。如果您的目录未启用,则无法计数,抱歉