我在这个脚本中遇到了一些问题:
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
如果我打开下载的子目录,例如 C:\ Users \ Dad \ Downloads \ Pictures ,它将关注该窗口而不是继续 Else 声明。
如果没有打开Windows资源管理器窗口,系统只会发出哔哔声,脚本会关闭。我在答案中选择了我的代码:https://www.autoitscript.com/forum/topic/30600-open-folder-with-autoit/。
我尝试为Run()
函数和text
参数标记此内容。
答案 0 :(得分:0)
出于某种原因,以下代码中不会出现2种不需要的行为:
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
答案 1 :(得分: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