the detailed folders returning incorrect data
Richard Gaskin
ambassador at fourthworld.com
Fri Jul 1 11:14:19 EDT 2016
Mark Waddingham wrote:
> There are two things to remember when dealing with files and folders:
>
> 1) You have to check for success of all your file operations -
> they can fail for all kinds of reasons which are entirely outwith
> your control, not just permissions issues.
>
> 2) There is a time-of-check to time-of-use problem with things
> related to unopened files / folders: just because permissions look
> okay before you start an operation, doesn't mean they will be okay
> by the time you start the operation, or will remain so throughout
> the operation.
...
> I just wonder if there is a better away to approach the problem you
> are trying to solve...
Over the years I've become a big fan of the sysError function, for both
of the reasons you outlined.
I call it after file I/O operations in conjunction with checking the
result, e.g.:
open file tFile
if the result is not empty then
answer the result &" ("& sysError() &")"
exit to top
end if
SysError returns the OS-suppplied error code for the most recent error
reported by the system to LiveCode. As such it often provides a
valuable clue about the specifics of the problem, whereas LC's error
strings tend to be more general.
For example, LC may report "can't open file" where sysError reports "2",
letting you know it's likely a path or file name issue.
On Windows I believe "access denied" will return "5" with sysError.
The more I've found sysError invaluable for learning the specifics of
I/O issues, the more I regret not having adopted it as a habit years
earlier. Tremendous time-saver.
--
Richard Gaskin
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
____________________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list