checking if a file is available?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
cu3e
Posts: 46
Joined: Mon May 23, 2011 10:03 am

checking if a file is available?

Post by cu3e » Tue Aug 30, 2011 4:44 pm

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".

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: checking if a file is available?

Post by Mark » Tue Aug 30, 2011 5:29 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: checking if a file is available?

Post by dunbarx » Tue Aug 30, 2011 8:05 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: checking if a file is available?

Post by Mark » Tue Aug 30, 2011 8:19 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: checking if a file is available?

Post by dunbarx » Wed Aug 31, 2011 3:13 am

Got it, Mark. Thanks.

Craig

cu3e
Posts: 46
Joined: Mon May 23, 2011 10:03 am

Re: checking if a file is available?

Post by cu3e » Wed Aug 31, 2011 9:34 am

Thank you!

Post Reply