open file

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
robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

open file

Post by robm80 » Fri Aug 01, 2014 6:30 am

I want to know if "foo.jpg is in "d:\Livecode\thumbnails".
This is the script:

Code: Select all

open file "d:\Livecode\thumbnails"
read from file ("d:\Livecode\thumbnails\") until EOF
if  "foo.jpg" is in it then
answer "eureka"
end if
but nothing happens.
What is the right script :?:

Thanks, Rob

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: open file

Post by Simon » Fri Aug 01, 2014 6:52 am

Hi Rob,
if there is a file "d:\Livecode\thumbnails\foo.jpg" then answer "eureka"

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: open file

Post by robm80 » Fri Aug 01, 2014 8:39 am

Thanks Simon,
but still I am missing something:

Code: Select all

put "foo" into tVar
 if there is a file "D:/Livecode/thumbnails/"&tVar&".jpg" then 
answer "eureka"
else
answer "nope"
end if
There is a foo.jpg in that map, but the answer is "nope". :?: :?: :cry:

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: open file

Post by Klaus » Fri Aug 01, 2014 11:52 am

Hi Rob,

Code: Select all

open file "d:\Livecode\thumbnails"
read from file ("d:\Livecode\thumbnails\") until EOF
if  "foo.jpg" is in it then
answer "eureka"
end if
you KNOW that "thumbnails" is in fact a folder but you try to handle it as a FILE?
What did you exspect?

When concatenating STRINGS (file and/or object names) you need to use PARENTHESIS!

Code: Select all

put "foo" into tVar
if there is a file ("D:/Livecode/thumbnails/" &t Var & ".jpg") then 
answer "eureka"
 else
answer "nope"
end if
That is because the engine will first evaluate the string INSIDE of the parens and will fail if there a no parens!
In your case teh engines stop at teh first expression and then stops, so this line:

Code: Select all

if there is a file "D:/Livecode/thumbnails/" &t Var&".jpg" then 
will only evaluate to this:

Code: Select all

if there is a file "D:/Livecode/thumbnails/" then
Best

Klaus

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: open file

Post by robm80 » Fri Aug 01, 2014 1:09 pm

Understood, thanks. Rob

Post Reply