File exists

Kay C Lan lan.kc.macmail at gmail.com
Sat Apr 2 13:53:09 EDT 2016


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.




More information about the use-livecode mailing list