What's the syntax to check if a local folder exists?
ambassador at fourthworld.com
Tue Jun 7 11:53:18 EDT 2011
Ken Ray wrote:
>> I went for a matching pair of one-liners, which worked very nicely:
>> if there is not a folder "this_folder" then create folder "this_folder"
>> if there is not a folder "this_folder/that_subfolder" then create folder
> Just a reminder - don't forget to check "the result" after you do your
> "create folder"; if the OS can't create it for some reason, you'll get
> something back in "the result". Here's an example:
> create folder "this_folder"
> put the result into tResult
> if tResult is not empty then
> answer "Could not create folder. Error reported was:" && tResult
> exit to top
> end if
I find that "the result" string is often vague, usually reporting only
that it can't create the folder but not why.
In recent years I've taken to appending "the result" with the value
return from sysError for a more specific OS error code:
answer "Could not create folder. Error reported was:" && tResult \
&"("& sysError() &")"
SysError returns the OS code, which often will tell you the difference
between an invalid path, or a folder that already exists, etc.
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
LiveCode Journal blog: http://LiveCodejournal.com/blog.irv
More information about the Use-livecode