Jump to content

A way to enumerating all open folders?


ioa747
 Share

Go to solution Solved by AspirinJunkie,

Recommended Posts

is there a more efficient way to enumerating all open folders?

I did this but i don't know if the $sPath = StringTrimLeft($sPath[15], 9)  is always in the same position

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7

#include <WinAPISysWin.au3>
#include <Array.au3>

Local $Test = Example()

_ArrayDisplay($Test, "$Test")

Func Example() ; CabinetWClass
    Local $aWindows, $i, $sPath, $index = 0
    Local $CabinetW[1][2] = [["hWnd", "Path"]]
    $aWindows = _WinAPI_EnumWindowsTop()
    For $i = 1 To $aWindows[0][0]
        If $aWindows[$i][1] = "CabinetWClass" Then
            ReDim $CabinetW[UBound($CabinetW) + 1][2]
            $index += 1
            $CabinetW[0][0] = $index
            $sPath = WinGetText($aWindows[$i][0])
            $sPath = StringSplit($sPath, @LF)
            $sPath = StringTrimLeft($sPath[15], 9) ; trim 'Address: '
            $CabinetW[$index][0] = $aWindows[$i][0]
            $CabinetW[$index][1] = $sPath
        EndIf
    Next
    Return $CabinetW
EndFunc   ;==>Example

Thanks!

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Thanks to @AspirinJunkie

Hear is  the conversion to proper array  for a more efficient way to enumerating all open folders

Hope is OK  :)

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#include <Array.au3>

Local $Test = _EnumAllOpenFolder()

_ArrayDisplay($Test, "$Test")

Func _EnumAllOpenFolder()
    Local $oShell = ObjCreate("Shell.Application")
    Local $sPath, $index = 0
    Local $aArray[$oShell.Windows.Count + 1][2] = [["hWnd", "Path"]]
    For $oWin In $oShell.Windows
        $index += 1
        $aArray[0][0] = $index
        $sPath = StringTrimLeft($oWin.LocationURL, 8) ; trim 'file:///'
        $sPath = StringReplace($sPath, "/", "\")
        $aArray[$index][0] = HWnd($oWin.HWND)
        $aArray[$index][1] = $sPath
    Next
    Return $aArray
EndFunc   ;==>_EnumAllOpenFolder

Thanks!

Edited:  add HWnd ( expression )

Edited:  add StringReplace($sPath, "/", "\")

Edited:  $oShell.Windows.Count + 1  instead ReDim  after   @seadoggie01 suggestion.  :)Thanks for that

Edited:  changed the Exampe2 to _EnumAllOpenFolder

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Instead of ReDim-ing your array with every iteration, you can initialize it with this:

Local $aArray[$oShell.Windows.Count + 1][2] = [["hWnd", "Path"]]

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...