早上好,
我的桌面上有 3 个文件夹,每个文件夹包含随机数量的文件夹。
文件夹 1
- 子文件夹:“here too”、“more stuff”、“Ranom stuff”、“Something Here”
文件夹 2
- 子文件夹:“and here”、“bored”、“Here stuff”、“here too”、“stuff here”
文件夹 3
- 子文件夹:“你好”、“你好”、“这里有更多东西”、“随机”、“这里随机”、“空间”
我要完成的工作:根据主文件夹列出每个单独列中的子文件夹,例如:
SelectionOne SelectionTwo SelectionThree
------------ ------------ --------------
0: here too 4: and here 9: Hello
1: more stuff 5: bored 10: Howdy
2: Ranom stuff 6: Here stuff 11: More Stuff here
3: Something Here 7: here too 12: Random
8: stuff here 13: Random here
14: Space
Enter Folder Numbers: 3, 14
然后可以通过选择的数字选择相应的文件夹,例如:
# from the 3, and 14 selection it would be the following selected:
'Something Here'
'Space'
到目前为止,我可以在单独的列中列出文件夹,只是不分配前一列的增量值。我面临的另一个问题是尝试为该数组选择正确的索引号并以某种方式将其与正确的文件夹相关联?即,当我选择 时,选择3,14
了第一列和第三列中的相应文件夹,但它也只显示为:
SelectionOne SelectionTwo SelectionThree
------------ ------------ --------------
0: here too 0: and here 0: Hello
1: more stuff 1: bored 1: Howdy
2: Ranom stuff 2: Here stuff 2: More Stuff here
3: Something Here 3: here too 3: Random
4: stuff here 4: Random here
5: Space
这是我所拥有的:
$Folder1 = Get-ChildItem -Path 'C:\users\Abraham\Desktop\Number 1'
$Folders1 = for ($i=0; $i -lt $Folder1.Count; $i++) {
[PSCustomObject]@{
FolderNames1 = "${i}: $($Folder1[$i].Name)"
}
}
$Folder2 = Get-ChildItem -Path 'C:\users\Abraham\Desktop\Number 2'
$Folders2 = for ($i=0; $i -lt $Folder2.Count; $i++) {
[PSCustomObject]@{
FolderNames2 = "${i}: $($Folder2[$i].Name)"
}
}
$Folder3 = Get-ChildItem -Path 'C:\users\Abraham\Desktop\Number 3'
$Folders3 = for ($i=0; $i -lt $Folder3.Count; $i++) {
[PSCustomObject]@{
FolderNames3 = "${i}: $($Folder3[$i].Name)"
}
}
$Count = ($Folders1.Count,$Folders2.Count,$Folders3.Count | Measure-Object -Maximum).Maximum
& {
for ($i=0; $i -lt $Count; $i++) {
[PSCustomObject]@{
SelectionOne = ($Folders1[$i].FolderNames1 | Format-List | Out-String).Trim()
SelectionTwo = ($Folders2[$i].FolderNames2 | Format-List | Out-String).Trim()
SelectionThree = ($Folders3[$i].FolderNames3 | Format-List | Out-String).Trim()
}
}
} | Format-Table -AutoSize -Wrap
$index = Read-Host -Prompt "Enter Folder Numbers" # Selected 3, 14
$index = $i.Trim() -split ','
foreach ($i in $index) {
# here would be correct folder for the corresponding
# array number.
# example:
<#
# from the selected 3, and 14.
# the following folders are selected
'Something Here'
'Space'
#>
}
谁能指出我正确的方向?
我觉得这是以前没有做过的事情,但是感觉这对未来的 Posh 用户来说会很方便。