Page 1 of 1

checking if a file is available?

Posted: Tue Aug 30, 2011 4:44 pm
by cu3e
I want to to program a function that my program check if a specific file is on a server. if this file is not there, it should report an error. How can a accomplish that?

Like a button. If I press on the button, the script looks if there is a file called "test.txt" on http://www.server.com. if yes, then button click goes to card "inside". If the file is not there, the button click goes to card "error".

Re: checking if a file is available?

Posted: Tue Aug 30, 2011 5:29 pm
by Mark
Hi,

Code: Select all

put url "http://economy-x-talk.com/bla.xyz" into myData
if the result contains "404" then
  -- doesn't exist
else
  -- do something with the data
end if
Mark

Re: checking if a file is available?

Posted: Tue Aug 30, 2011 8:05 pm
by dunbarx
Mark.

Your suggestion will show whether the url exists, not whether a certain file within that url does. I was intrigued by this question. Is there a "there is a" operator/methodology for files within a webpage, similar to that capability within the LC IDE or within ones desktop environment? Wouldn't you have to examine the index within the webpage, and wouldn't that require admin access?

Craig Newman

Re: checking if a file is available?

Posted: Tue Aug 30, 2011 8:19 pm
by Mark
Craig,

Craig, in those cases that a server responds by parsing the url and returning some data, instead of just returning the contents of a file, one should either find a way to communicate with that server, e.g. by writing a php function, or one should use ftp or ssh, but OP seems to expect he can use http, which led me to the answer I posted previously.

Kind regards,

Mark

Re: checking if a file is available?

Posted: Wed Aug 31, 2011 3:13 am
by dunbarx
Got it, Mark. Thanks.

Craig

Re: checking if a file is available?

Posted: Wed Aug 31, 2011 9:34 am
by cu3e
Thank you!