Sign in to follow this  
Followers 0
JLC123

Wait for file to exist

8 posts in this topic

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

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by BPBNA

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by BPBNA

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0