【发布时间】:2021-01-02 06:32:12
【问题描述】:
我有一个列表视图,我通过运行 Get-ChildItem 来填充文件夹的内容。我想根据它们所在的文件夹将项目与 listviewgroup 分组。我的问题是我似乎无法动态地做到这一点。
例如,我使用 Get-ChildItem 5 个文件夹,即:
\\1
\\2
\\3
\\4
\\5
所以我想创建 5 个组等。下面是我到目前为止尝试的代码:
$getgroups = Get-ChildItem $path -Filter $whattosearchfor -Recurse:$recurse | % {split-path $_.FullName } | Sort-Object -Descending | select-object -Unique
for($testingI = 1;$testingI -lt $getgroups.length;$testingI++){
$testingII = $testingI
$testingII = New-Object System.Windows.Forms.ListViewGroup
$testingII.Header = $_
$testingII.Name = $_
[system.void]$listView1.Groups.Add($testingII)
}
#$getgroups | % {
# #$xCounter = $_
# $xCounter = New-Object System.Windows.Forms.ListViewGroup
# $xCounter.Header = $_
# $xcounter.Name = $_
# $listView1.Groups.Add($xCounter)
# $x++
# }
【问题讨论】:
-
找到了一个解决办法,使用hashtables版主可以关闭线程thxxx
-
您可以发布您的解决方案以帮助遇到相同或类似问题的其他人,或者如果您认为它对其他人没有帮助,您可以删除您的问题。 ;-)
-
...或者,如果您不想帮助他人,您可以删除您的问题。您不需要版主。
标签: powershell powershell-2.0 powershell-3.0 powershell-4.0