2015-04-30 36 views

回答

0

如何SEACH和運行exe文件存在子目錄

_FileListToArrayRec()內位於子文件夾(-files)。

我已經嘗試使用runwait的路徑名稱工作正常,但我想搜索,因爲我的子文件夾不斷變化每天。

識別使用_FileListToArrayRec()關於文件夾,並相應地設置Run()的(或RunWait()的)第一個參數。

實施例:

#include <File.au3> 

Global Enum $RFS_ERROR_RUN = 2 

Global Const $g_sFileName = 'notepad.exe', _ 
      $g_sFilePath = 'C:\', _ 
      $g_sFileMsg = 'file   : "%s"\n(sub-)folder : "%s"\nlocated at : "%s"\n' 

_RunFromSubfolder($g_sFileName, $g_sFilePath) 

Func _RunFromSubfolder(Const $sFile, Const $sFolder) 
    Local  $sMessage = '' 
    Local  $iError = 0, _ 
       $iExtd = 0, _ 
       $iPID  = 0 
    Local Const $aItems = _FileListToArrayRec($sFolder, $sFile, $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) 

    If @error Then 

     $iError = @error 
     $iExtd = @extended 

    Else 

     $sMessage = StringFormat($g_sFileMsg, $sFile, $sFolder, $aItems[1]) 
     $iExtd = $aItems[0] 
     $iPID  = Run($aItems[1]) 

     If @error Then 

      $iError = $RFS_ERROR_RUN 
      $iExtd = @error 

     EndIf 

     ConsoleWrite($sMessage) 

    EndIf 

    Return SetError($iError, $iExtd, $iPID) 
EndFunc 

控制檯輸出:

file   : "notepad.exe" 
(sub-)folder : "C:\" 
located at : "C:\...\...\notepad.exe"