我正在尝试获取一个特定子文件夹结构的递归文件列表,然后将它们保存到一张表中,以便我可以使用 foreach 循环来处理每一行。 我有以下代码:
$table = get-childitem -recurse | where {! $_.PSIsContainer} | Format-Table Name, Length
foreach ($row in $table)
{
$row[0]
$row[1]
}
如果我尝试直接输出$table
,它看起来完美,所有文件都有两列数据。如果我尝试使用foreach来逐步遍历(如上所述),我会收到"无法对类型为Microsoft.PowerShell.Commands.Internal.Format.FormatEndData的对象进行索引。"
的错误消息。我做错了什么?