2015-11-27 22 views
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. 如果我有下载的子目录开放,像C:\ Users \用户爸爸\下载\图片,它将关注该窗口,而不是继续到Else声明。

  2. 如果没有打开Windows资源管理器窗口,系统会向我发出蜂鸣声,脚本关闭。我在这里回答了我的代码:https://www.autoitscript.com/forum/topic/30600-open-folder-with-autoit/

我试图给Run()函数和text参数加上标签。

+0

如果删除“&”,则解析2.。 –

+0

出于某种原因,删除“&”也解决了1.所以,我很好奇为什么。 –

回答

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 
+0

问题是,当您连接两个字符串“Explorer.exe”和“C:\ Users \ Dad \ Downloads”时,您错过了一个空格,就像您在问题中所做的那样。基本上你试图运行这个命令:'Explorer.exeC:\ Users \ Dad \ Downloads'。这是行不通的。 – mrt

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