Page 1 of 1

open file

Posted: Fri Aug 01, 2014 6:30 am
by robm80
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

Re: open file

Posted: Fri Aug 01, 2014 6:52 am
by Simon
Hi Rob,
if there is a file "d:\Livecode\thumbnails\foo.jpg" then answer "eureka"

Simon

Re: open file

Posted: Fri Aug 01, 2014 8:39 am
by robm80
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:

Re: open file

Posted: Fri Aug 01, 2014 11:52 am
by Klaus
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

Re: open file

Posted: Fri Aug 01, 2014 1:09 pm
by robm80
Understood, thanks. Rob