Jump to content

Automatically launch executable when it exists


Recommended Posts

Hello, I am trying to write an AutoIt script that will continuously check a specific network directory for new files, if any new files that are found that have the .exe extension , then I want to launch said application.

- I know the Major & Minor Revision numbers for these applications but not the "Developer" numbers (i.e. GF_V2.1.xxx.xxx)

- The Network directory will never change

- Other file types will exist in this network directory, I need to ignore them.

- 200+ older exe's already exist in this network directory, I only want new files to be launched

The difficulty I'm having is that I don't actually know the complete name of the file, so I cannot use the "FileExists" function to my knowledge.

Any help would be very much appreciated

Link to comment
Share on other sites

Check out $aFileList = _FileListToArray ($Path,$Filter,1,True); you can use $FILTER to only return EXEs and even partial names

then this...

 

$ADATE = FileGetTime($aFileList[$I], 1, 0);1 = get created date
    $SDATE = $ADATE[0] & "/" & $ADATE[1] & "/" & $ADATE[2];split and format
    $Daysold = _DateDiff("D", $SDATE, _NowCalcDate());get date difference if you need it

 

Link to comment
Share on other sites

Loop from all the exe files (maybe filelisttoarray). check date creation then shellexecute.

maybe something like this

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; List all the files and folders in the desktop directory using the default parameters.
    $networkDirectoy=@DesktopDir
    Local $aFileList = _FileListToArray($networkDirectoy, "*.exe")
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    EndIf
    ; Display the results returned by _FileListToArray.
    _ArrayDisplay($aFileList, "$aFileList")
    for $i=1 to $aFileList[0]
        ConsoleWrite($networkDirectoy & "\" & $aFileList[$i] & @CRLF)
        ;check for date creation or anything you need
    Next
EndFunc   ;==>Example

 

Saludos  

Link to comment
Share on other sites

Another way get file list like this get all files name using.

_FileListToArray()

and then save it as .INI and compare you new array with old saved INI file .

edit:::

you can use this function to convert array to ini or ini to array.

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

#include <Array.au3>
#include <File.au3>

Global $defaultSeparator = Opt("GUIDataSeparatorChar", "|")
Global $defaultSeparatorString = "<%Separator%>"
Global $networkDirectory  = @DesktopDir

$sScriptName = @Compiled ? @ScriptName : StringRegExpReplace(@AutoItExe, ".+\\", "")

While 1 ;Avoiding from double processing
    $aList = ProcessList($sScriptName)
    If $aList[0][0] = 1 Then ExitLoop
    For $i = 1 To $aList[0][0]
        If $aList[$i][1] <> @AutoItPID Then ProcessClose($aList[$i][1])
    Next
WEnd


    Local $aFileList = _FileListToArray($networkDirectory, "*exe",1)
    If @error = 1 Then
        MsgBox(0, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox(0, "", "No file(s) were found.")
        Exit
    EndIf

    _arrayToIni("Ntwrk.ini","EXE Files",$aFileList) ;Create a list of all files here desktop



While 1

    $aFileList = _FileListToArray($networkDirectory, "*exe",1)
     $oldlist = IniReadSection("Ntwrk.ini","EXE Files")
     If Not @error Then

         If ($oldlist[0][0]-1) > $aFileList[0] Then ;Incase delete reset EXE file list
        $aFileList = _FileListToArray($networkDirectory, "*exe",1)
         FileDelete(@desktopdir&"\Ntwrk.ini")
         _arrayToIni("Ntwrk.ini","EXE Files",$aFileList)
         EndIf

     If ($oldlist[0][0]-1) < $aFileList[0] Then
         $aFileList = _FileListToArray($networkDirectory, "*exe",1)
         $L = $aFileList[0]
         $find=_ArrayFindAll($oldlist,$aFileList[$L])
         If @error = 6 Then
             $aFileList = _FileListToArray($networkDirectory, "*exe",1)
             $L = $aFileList[0]
             $ans = MsgBox(4,"Alert","New file is: "& $aFileList[$L] &" Do You Want Execute???")
             If $ans = 7 Then
                 WinClose("Alert")
             ElseIf $ans = 6 Then
                 $aFileList = _FileListToArray($networkDirectory, "*exe",1,True)
                 $L = $aFileList[0]
                 ShellExecute($aFileList[$L])
             EndIf
             _arrayToIni("Ntwrk.ini","EXE Files",$aFileList)
             EndIf
     EndIf
     EndIf

WEnd


Func _arrayToIni($hFile, $sSection, $aName) ;;;BY Detefon
    Local $iLines = UBound($aName)
    Switch UBound($aName, 2)
        Case 0
            Local $sTemp = ""
            For $ii = 0 To $iLines - 1
                $aName[$ii] = StringReplace($aName[$ii], @LF, "At^LF")
                $sTemp &= $ii & "=" & $aName[$ii] & @LF
            Next
            IniWriteSection($hFile, $sSection, $sTemp, 0)
        Case Else
            Local $aTemp[1], $sString = "", $iColumns = UBound($aName, 2)
            For $ii = 0 To $iLines - 1
                For $jj = 0 To $iColumns - 1
                    $aName[$ii][$jj] = StringReplace($aName[$ii][$jj], $defaultSeparator, $defaultSeparatorString)
                    $sString &= $aName[$ii][$jj] & $defaultSeparator
                Next
                _ArrayAdd($aTemp, StringTrimRight($sString, 1))
                $sString = ""
            Next
            _ArrayDelete($aTemp, 0)
            _arrayToIni($hFile, $sSection & "#" & $iColumns & "#" & $defaultSeparator & "#" & $defaultSeparatorString, $aTemp)
    EndSwitch
EndFunc   ;==>_arrayToIni

Try this one

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...