When specialFolderPath() fails

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
sritcp
Posts: 424
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

When specialFolderPath() fails

Post by sritcp » Sun Feb 09, 2020 8:17 pm

I have a file named lorem.html on my desktop.
In message box,

Code: Select all

put there is a file  specialFolderPath("desktop") & "/" & "lorem.html"
returns false. Actually, it returns false/lorem.html
When I type

Code: Select all

put specialFolderPath("desktop")
it returns /Users/MyName/Desktop
When I copy the above returned result and stick it in the original command in place of specialFolderPath("desktop") as in

Code: Select all

put there is a file  "/Users/MyName/Desktop/lorem.html"
it returns true

What gives? Could it be that my Desktop folder is inside my iCloud folder which is transparent when the path is called literally but interferes somehow when specialFolderPath is used?

Thanks,
Sri

SparkOut
Posts: 2067
Joined: Sun Sep 23, 2007 4:58 pm

Re: When specialFolderPath() fails

Post by SparkOut » Sun Feb 09, 2020 8:48 pm

No, the boolean evaluation is resolving wrongly, you should use parentheses to ensure the value to be evaluated is concatenated first:

Code: Select all

put there is a file (specialFolderPath("desktop") & "/" & "lorem.html")
The way you have it, the interpreter is treating it as two boolean tests with an and conditional operator

Code: Select all

put there is a file (specialFolderPath("desktop"))
and
("/" & "lorem.html")
The first condition fails, because there is never a file with that name so the second (erroneous) condition is never evaluated as the conditional operator is an "and"

The engine always tries to resolve variable contents but it always helps to use parentheses to force the correct resolution of values. In this case it is vital.

Klaus
Posts: 11495
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: When specialFolderPath() fails

Post by Klaus » Sun Feb 09, 2020 9:13 pm

EXACTLY! :D

Or create a variable first, which is also helpful when debugging!

Code: Select all

...
put specialFolderPath("desktop") & "/" & "lorem.html" into tFile
put there is a file tFile then
...

sritcp
Posts: 424
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: When specialFolderPath() fails

Post by sritcp » Sun Feb 09, 2020 9:40 pm

Darn!
Do you know how many times in the past I have heard Klaus shout (in all caps) about this very point?
I still stepped into it!
Putting it into a variable first should guard me against this pitfall.

Thanks,
Sri

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”