File exists

RM richmondmathewson at gmail.com
Sat Apr 2 14:13:14 EDT 2016



On 2.04.2016 20:53, Kay C Lan wrote:
> On Sat, Apr 2, 2016 at 4:48 PM, JB <sundown at pacifier.com> wrote:
>> If I open a file for read or write and the file does
>> not exist it will be created.
> Just to clarify, that statement is incorrect.
>
> If you open a file for 'write' and the file does not exist, it will be created.
>
> if you open a file for 'read' and the file does not exist 'the result'
> will be "can't open that file" and NO file is created.
>
> on mouseUp
>     set the defaultFolder to specialFolderPath("documents")
>     open file "this is a test.lcdoc" for read
>     if  (the result is "can't open that file") then
>        --check if a file was created
>        if (there is a file "this is a test.lcdoc") then
>           answer "A file was created!"
>        else
>           answer "The file was NOT created."
>        end if
>     else
>        answer "You can read from it now!"
>     end if
> end mouseUp
>
> Please also note that Richmond's example is misleading. If you use
> 'read from file' without first using  'open file' then regardless of
> whether the file exists or not, 'it' will always be empty.

Whoops: sorry about that one.

Richmond.

>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list