Jump to content

Wait for file to exist


Recommended Posts

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

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

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

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

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 by BPBNA
Link to comment
Share on other sites

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

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 by BPBNA
Link to comment
Share on other sites

  • 11 years later...
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 by Jasp402
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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