Page 1 of 1

evaluating if a file is there before reading

Posted: Thu Sep 09, 2010 7:30 pm
by magice
In the project i am currently working on, I initialize an array by reading from a txt file on start up. I use the following code

Code: Select all

on importText   
   global tDataLoad
   open file "downloader.ini" for read   
   read from file "downloader.ini" until eof   
   put it into tDataLoad   
   close file "downloader.ini"  
end importText
That works fine. But In the event that the "downloader.ini" file has been deleted I want to instead initialize the tDataLoad array from a default copy saved as a custom property of the stack. I have the custom property saved as cBlankINI of stack "downloader". That part works fine. Where I am having trouble, is in the evaluation of the existence of file "downloader.ini" what would be the proper way to determine if the file exists before reading from it?

Re: evaluating if a file is there before reading

Posted: Thu Sep 09, 2010 7:54 pm
by bn
Magice,
look at "there is" in the dictionary. I tells you if the file you want to look at really exists. You have to give it the correct path and filename.

regards
Bernd

Re: evaluating if a file is there before reading

Posted: Fri Sep 10, 2010 11:23 am
by Klaus
Hi magice,

yep, "if there is a file xyz" will do the job.

Hint!
To save a lot of typing get used to the URL syntax like this:

Code: Select all

on importText   
   global tDataLoad
  if there is a file "downloader.ini" then
    put url("file:" & "downloader-ini") into tDataLoad
    ## See, just ONE line :-)
   else
    ## do your else thing
  end if   
end importText
Best

Klaus

Re: evaluating if a file is there before reading

Posted: Fri Sep 10, 2010 2:02 pm
by magice
Thank you Bernd, that was exactly what I needed to know. And thank you Klaus for the extra hint. Unfortunately I already did the extra typing.

Re: evaluating if a file is there before reading

Posted: Fri Sep 10, 2010 3:35 pm
by Klaus
Hi magice,

my hint will also work with new scripts :D