0

我遇到了这个脚本的一些问题:

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. 如果我打开了Downloads的子目录,例如C:\Users\Dad\Downloads\Pictures,它将聚焦该窗口而不是继续Else语句。

  2. 如果没有打开 Windows 资源管理器窗口,系统只会对我发出哔哔声,然后脚本关闭。我在这里的答案中选择了我的代码:https ://www.autoitscript.com/forum/topic/30600-open-folder-with-autoit/ 。

我试图为Run()函数和text参数标记它。

4

2 回答 2

0

这是您想要做的一个工作示例。基本上,您的代码与您要查找的目录的子字符串匹配。这就是它激活具有相同子目录的窗口的方式。

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
于 2015-11-27T19:09:54.937 回答
0

出于某种原因,以下代码不会出现两种不需要的行为:

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
于 2015-11-27T18:18:49.103 回答