0

I've run into a few issues with this script:

If WinExists ("[CLASS:CabinetWClass]", "Address: C:\Users\Dad\Downloads") Then
    WinActivate ("[CLASS:CabinetWClass]", "Address: C:\Users\Dad\Downloads")
Else
    Run("Explorer.exe" & "C:\Users\Dad\Downloads")
Endif
  1. If I have a subdirectory of Downloads open, like C:\Users\Dad\Downloads\Pictures, it will focus that window rather than continuing to the Else statement.

  2. If there are no Windows Explorer windows open, the system just beeps at me, and the script closes. I picked up my code in the answers here: https://www.autoitscript.com/forum/topic/30600-open-folder-with-autoit/ .

I tried to tag this for the Run() function and text parameter.

Wolfpack'08
  • 3,982
  • 11
  • 46
  • 78

2 Answers2

0

For some reason, neither of the 2 unwanted behaviors occur with the following code:

If WinExists ("[CLASS:CabinetWClass]", "Address: C:\Users\Dad\Downloads") Then
    WinActivate ("[CLASS:CabinetWClass]", "Address: C:\Users\Dad\Downloads")
Else
    Run("Explorer.exe C:\Users\Dad\Downloads") #this line was changed.
Endif
Wolfpack'08
  • 3,982
  • 11
  • 46
  • 78
  • The problem is that you missed a whitespace when you concatenate the two strings "Explorer.exe" and "C:\Users\Dad\Downloads" as you did in your question. Basically you tried to run this command: `Explorer.exeC:\Users\Dad\Downloads`. This just can't work. – Andreas Nov 29 '15 at 02:53
0

This is a working example of what you want to do. Basically your code is matching a sub string of the directory you are looking for. That is way it is activating windows with the same subdirectory.

FindorOpenExporer("C:\Users\Dad\Downloads")

Func FindorOpenExporer($sPath)
    Local $aWinList = WinList("[CLASS:CabinetWClass]")

    ;if no Exporer windows are found
    If IsArray($aWinList) = False Then
        StartEplorer($sPath)
        Return 0
    EndIf

    ;if explorer windows are found
    For $i = 1 To UBound($aWinList) - 1
        $sWinText = WinGetText($aWinList[$i][1])

        ;activates the window and returns the window handle if it is found
        If StringInStr($sWinText, "Address: " & $sPath) Then
            WinActivate($aWinList[$i][1])

            ;returns the window handle
            Return $aWinList[$i][1]
        EndIf
    Next

    StartEplorer($sPath)
EndFunc   ;==>FindorOpenExporer

Func StartEplorer($sPath)
    Run("Explorer.exe " & $sPath)
EndFunc   ;==>StartEplorer
MrAutoIt
  • 785
  • 6
  • 21