gripper Posted November 18, 2012 Share Posted November 18, 2012 (edited) Hi members,Have a question regarding ‘FileExist” and if this is the right direction I should be going in.I have a script that runs a program on my computer and after the program is running it looks for a pop up completion window with an OK button. My script will click that and close the program and then continue with the rest of the scripting procedures. This is running perfectly.But, I have an issue and that is I now need to run addition instances of this program and each one has the same title bar and text info. One thing this program does is when completed it will create a summary.txt file within its home directory.So I want to switch gears here and perhaps instead of the system looking for a popup completion window which is confusing the script; instead look at the directory and wait for the creation of summary.txt file to continue. I can suppress the pop up window and take that out of the equation altogether and hopefully have the script look for the creation of the file as its “visual trigger” to move on.So for instance if program 1 is in this location “c:softwareprogram1program.exe” it will run and when done will create summary.txt file at “c:softwareprogram1summary.txt”. At the same time this is running another program installed in “c:Softwareprogram2… “ may be running at the same time and will, upon completion create its own summary.txt file in its home directory.I looked at ‘FileExist” but I am lost on how to make that act as a live listening trigger/agent for the script. The only thing that I could think of is some type of “Do” loop but I am not particularly skilled in loops and I may be wrong as to the use of that.I was hoping somebody could give me some assistance and direction.Thanks Edited November 18, 2012 by gripper Link to comment Share on other sites More sharing options...
JohnOne Posted November 18, 2012 Share Posted November 18, 2012 Here is an example of one way you could go about your task. #include <File.au3> #include <Array.au3> ; just for testing $Path = "c:software" $Summary = "summary.txt" $iCount = 0 ; to check how many folders have been processed $AFolders = _FileListToArray($Path, "*", 2) ; lists all folders to array _ArrayDisplay($AFolders) ; just for testing While 1 ; $AFolders[0] contains the amount of folders found For $i = 1 To $AFolders[0] ; loop through all found folders If FileExists($Path & $AFolders[$i] & $Summary Then ; your summery file exists here ; you can process it, but must delete, or rename it after, or it might find it twice $iCount += 1 ; you processed a file so increase the count EndIf Next If $iCount >= $AFolders[0] Then ;you processed them all ExitLoop ; bail out of loop EndIf WEnd Fr33b0w 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Decipher Posted November 18, 2012 Share Posted November 18, 2012 (edited) Here is an example of one way you could go about your task. I call this work of art the file iteration simplificationer or maybe not. expandcollapse popupfunc _summary($sfile, $isdir) If stringinstr($sfile, "summary.txt") then ;Do Something with that file - $sfile is the fully qualified file path to bla endif if $isdir than ;Do something with it maybe? endif endfunc _FileListEx("C:Software", "_Summary") Func _FileList_Ex($s_Dir = @WorkingDir, $s_Func = "") ConsoleWrite(@CRLF & "!>Root Directory is set to " & $s_Dir & " and will be preserved." & @CRLF) Local $a_Directory_List[2] = ["", $s_Dir] __FileList_Ex($a_Directory_List, $s_Func) ConsoleWrite(@CRLF & "!> Search Finished!" & @CRLF & @CRLF) EndFunc ;==>_FileList_Ex Func __FileList_Ex(ByRef $a_Directory_List, $s_Func) ; Recursive Local $iFile = 0, $sDir = _ArrayPop($a_Directory_List) If Not IsArray($a_Directory_List) Then Return FileChangeDir($sDir) If FileExists($sDir) Then ConsoleWrite(@CRLF & ">Search: " & $sDir) Else Return EndIf Local $h_Files = FileFindFirstFile("*.*") While 1 Local $sFile = FileFindNextFile($h_Files) If @error Then If FileExists($sDir) Then ConsoleWrite(@CRLF & "+> " & $iFile & " File(s)" & @CRLF) If IsArray($a_Directory_List) Then __FileList_Ex($a_Directory_List, $s_Func) ExitLoop EndIf $iFile += 1 $sFile = _PathFull($sFile) Local $Is_Dir = False If StringInStr(FileGetAttrib($sFile), "D") Then _ArrayAdd($a_Directory_List, $sFile) $Is_Dir = True EndIf Call($s_Func, $sFile, $Is_Dir) WEnd FileClose($h_Files) EndFunc ;==>__FileList_Ex I wrote this recursive function a couple of days ago, maybe you will find it of use + just call the function with your own that way you can forget about the painful loops. *Edit You'll need these at the top of your script for it to work. #include <Array.au3> #include <File.au3> I'm really starting to hate Google Chrome.... Edited November 18, 2012 by Decipher Fr33b0w 1 Spoiler Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now