Good morning,
I have 3 folders on my desktop that contain a random amount of folders on each one.
Folder 1
- Sub-Folders: "here too", "more stuff", "Ranom stuff", "Something Here"
Folder 2
- Sub-Folders: "and here", "bored", "Here stuff", "here too", "stuff here"
Folder 3
- Sub-Folders: "Hello", "Howdy", "More Stuff here", "Random", "Random here", "Space"
What I'm trying to accomplish: List the sub-folders in each separate columns based off the main folder, like:
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
Then be able to select the corresponding folder by the number selected such as:
# from the 3, and 14 selection it would be the following selected:
'Something Here'
'Space'
So far, this I can list the folders in separate columns, just not assign an incremented value of the previous column. The other problem I face is attempting to select the correct index number for that array and somehow correlate it to the correct folder? i.e., when I selected 3,14
, the corresponding folders from column one and 3 were selected but, it only displays as this as well:
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
Here's what I have:
$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'
#>
}
Can anyone point me in the right direction?
I feel like this is something that hasn't been done before but, feel like it would be handy for future Posh users.