Continue if file found

Just starting out? Need help? Post your questions and find answers here.
abc123
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Apr 18, 2007 9:27 pm

Continue if file found

Post by abc123 »

Can anyone help me with a basic function, find a file and if it dont exist repeat find until it does then continue?
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

abc123 wrote:Can anyone help me with a basic function, find a file and if it dont exist repeat find until it does then continue?
Why would it help to keep looking for a file that doesn't exist?

@EDIT: My answer was supposed to include some code but byo beat me to it, including coding the delay to prevent the infinite loop. The Submit button is a little too close to the Preview button sometimes. :wink: )
Last edited by Demivec on Mon Oct 15, 2007 8:39 pm, edited 1 time in total.
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Post by byo »

I'd use this:

Code: Select all

Repeat
Delay(10)
Until FileSize(file.s) >= fileSize.l
But you have to make sure the file is being created or you'll be stuck in the loop. I'm not sure how much CPU it'll use but that Delay can help you.

:?

hmm... I'm sure it's bad programming.

You could use:

Code: Select all

Repeat
Delay(10)
Until FileSize(file.s) > -1
if you don't need to check the file's integrity. I'm pretty sure it's bad programming as well as you may get stuck with no error catching. :lol:

.
abc123
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Apr 18, 2007 9:27 pm

Post by abc123 »

Demivec wrote:
abc123 wrote:Can anyone help me with a basic function, find a file and if it dont exist repeat find until it does then continue?
Why would it help to keep looking for a file that doesn't exist?
I have exe that reads of a file created with that exe, so sometimes it shows up with nothing cause the file hasnt been created.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post by #NULL »

you can also use a flag in you mainloop (if you have one)
and just leave out actions according to the existence of that file.

Code: Select all

Repeat
  fileExists = (0 Or (FileSize(filenames$) >= 0))
  ;do general stuff
  ;do general stuff
  If FileExists
    ;do special stuff
    ;do special stuff
  Else
    ;do other stuff
    ;do other stuff
  EndIf
  ;do general stuff
  ;do general stuff
  If thisOrThat
    quit=1
  EndIf
  Delay(20)
Until quit
Irene
Enthusiast
Enthusiast
Posts: 461
Joined: Thu Oct 04, 2007 12:41 pm

Post by Irene »

abc123 wrote:
Demivec wrote:
abc123 wrote:Can anyone help me with a basic function, find a file and if it dont exist repeat find until it does then continue?
Why would it help to keep looking for a file that doesn't exist?
I have exe that reads of a file created with that exe, so sometimes it shows up with nothing cause the file hasnt been created.
But if the application doesn't create the file in the first place, why make a loop to continually check for a file that won't ever be there?
Post Reply