JLC123 Posted July 12, 2006 Share Posted July 12, 2006 Sorry for posting such a simple question, but I've been coding since 8:30 this morning and I'm fried. I just need a little While/Wend loop to wait for my file to exist and give up after 5 minutes and exitloop. Can anyone slap that together for me please? Thanks! Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
Daniel W. Posted July 12, 2006 Share Posted July 12, 2006 AdlibEnable( "_Exists" , 1000 ) Global $path = "" ; Your path Global $Timer = 0 While 1 Sleep( 100 ) WEnd func _Exists() If $Timer < 1000 * 60 * 5 Then $Timer += 1000 If FileExists( $path ) Then Return 1 Else Return 0 EndIf EndIf EndFunc Maybe this --------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote] Link to comment Share on other sites More sharing options...
Briegel Posted July 12, 2006 Share Posted July 12, 2006 Is this what you want? While 1 Sleep(100) If FileExists("yourpath\yourfile") = 1 Then Sleep(300000) ExitLoop() EndIf WEnd Link to comment Share on other sites More sharing options...
JLC123 Posted July 12, 2006 Author Share Posted July 12, 2006 Both of those scripts wait 5 minutes even if the file I'm waiting for already exists. I need the loop to end as soon as the file exists and to wait no more than 5 minutes for that event to occur. Make sense? Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
JLC123 Posted July 12, 2006 Author Share Posted July 12, 2006 ok - this seems to do the trick: $Timer = 0 While 1 If $Timer < 300000 Then If FileExists("u:\jlc.ini") Then ExitLoop Else $Timer = +1000 EndIf EndIf WEnd Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
BPBNA Posted July 12, 2006 Share Posted July 12, 2006 (edited) I don't think that would go for the right amount of time. It adds a second every time it loops, chances are a loop will take much less than a second try $begin = TimerInit() While TimerDiff($begin) < 300000 If FileExists("u:\jlc.ini") then ExitLoop WEnd Edited July 12, 2006 by BPBNA Link to comment Share on other sites More sharing options...
Simucal Posted July 12, 2006 Share Posted July 12, 2006 I don't think that would go for the right amount of time. It adds a second every time it loops, chances are a loop will take much less than a second try $begin = TimerInit() While TimerDiff($begin) < 300000 If FileExists("u:\jlc.ini") then ExitLoop WEnd I dont think I would make it Exitloop if the fileexists, that is the same result you will get if the file doesnt exist in 5 minutes. Also, put a sleep in there, that will be a hard hitting loop for the CPU. AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
BPBNA Posted July 12, 2006 Share Posted July 12, 2006 (edited) Yeah I didn't really think that through I guess, but he can replace the Exitloop with whatever code he wanted to be there when it finds it. $begin = TimerInit() While TimerDiff($begin) < 300000 If FileExists("u:\jlc.ini") then ;insert code EndIf WEnd Edit: Forgot to close the code tag Edited July 12, 2006 by BPBNA Jasp402 1 Link to comment Share on other sites More sharing options...
Jasp402 Posted January 29, 2018 Share Posted January 29, 2018 (edited) Quote waitForExistFile('D:\New Text Document.txt',30000) Func waitForExistFile($sPath, $iTimeOut) $sBegin = TimerInit() While TimerDiff($sBegin) < $iTimeOut If FileExists($sPath) then Return True Else ContinueLoop EndIf Return false WEnd EndFunc Returns true if the file exists or false if the time runs out Edited January 29, 2018 by Jasp402 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 29, 2018 Moderators Share Posted January 29, 2018 Jasp402, I take it you did not notice that the post above yours dates from nearly 12 years ago! Please do not necro-post like this again. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts