This posting is related to a prior posting:
# [
Add all dirPaths open in windows explorer to an array](https://forums.powershell.org/t/add-all-dirpaths-open-in-windows-explorer-to-an-array/20339)
[PowerShell Help](https://forums.powershell.org/c/powershell-qa/5)
I am trying to make a list (array) of all directories open in Windows Explorer, and to make sure the list does not include more than one (1) list item containing any particular path, i.e., no path should appear twice in the array oven though more the directory was open in more than one Windows Explorer window when the script was run. But a directory that is open twice in Windows Explorer does appear twice in the list. I’m only at Chap. 3 in Learn_PowerShell_in_a_Month_of_Lunches_4th Ed., and my ill-informed attempts at searching for an explanation on the Web have proved fruitless.
Here’s my code:
Function Get-CurrentLine {
# https://www.jaapbrasser.com/quicktip-determine-current-line-number-in-powershell/
$Myinvocation.ScriptlineNumber
}
Write-Host "$(Get-CurrentLine) ---------$([char]10)"
$NuDirList = ''
$NuDirList = @(
(New-Object -ComObject 'Shell.Application').Windows() |
ForEach-Object {
$localPath = ($_.Document.Folder.Self.Path).Trim()
#$localPath = Convert-Path $localPath.Trim()
if ($NuDirList.Contains($localpath)) {
$('$localpath is already in the list')} else
{
$_.Document.Folder.Self.Path}
}
)
foreach ($localPath in $NuDirList){"Line $(Get-CurrentLine) $($localPath)-$([char]10)"}
Here’s what my code returns:
PS C:\Users\marc> E:\Apps\UtilPS\Lists_aaa.ps1
7 ---------
Line 23 E:\-
Line 23 E:\Apps\UtilPS-
Line 23 E:\-
Line 23 F:\Install\PyCharm\HelpMe\IssuesOstg-
Etc.
Any suggestions would be much appreciated.
Thanks, Marc