Page 1 of 1

When specialFolderPath() fails

Posted: Sun Feb 09, 2020 8:17 pm
by sritcp
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

Re: When specialFolderPath() fails

Posted: Sun Feb 09, 2020 8:48 pm
by SparkOut
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.

Re: When specialFolderPath() fails

Posted: Sun Feb 09, 2020 9:13 pm
by Klaus
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
...

Re: When specialFolderPath() fails

Posted: Sun Feb 09, 2020 9:40 pm
by sritcp
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