File exists

classic Classic list List threaded Threaded
9 messages Options
JB
Reply | Threaded
Open this post in threaded view
|

File exists

JB
If I open a file for read or write and the file does
not exist it will be created.  Is there a way to see
if the file exists before opening it?  I do not want
a file to be created if it does not exist.  I guess I
could check the creation date and if it was just
created then delete it but I was wondering if there
is a better way.

JB

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
JB
Reply | Threaded
Open this post in threaded view
|

Re: File exists

JB
Files will do it;
I forget so easily.

JB



> On Apr 2, 2016, at 1:48 AM, JB <[hidden email]> wrote:
>
> If I open a file for read or write and the file does
> not exist it will be created.  Is there a way to see
> if the file exists before opening it?  I do not want
> a file to be created if it does not exist.  I guess I
> could check the creation date and if it was just
> created then delete it but I was wondering if there
> is a better way.
>
> JB
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: File exists

Thierry Douez
In reply to this post by JB
Hi,

there is a file ".."

HTH,

Thierry


2016-04-02 10:48 GMT+02:00 JB <[hidden email]>:

> If I open a file for read or write and the file does
> not exist it will be created.  Is there a way to see
> if the file exists before opening it?  I do not want
> a file to be created if it does not exist.  I guess I
> could check the creation date and if it was just
> created then delete it but I was wondering if there
> is a better way.
>
> JB
>
--
------------------------------------------------
Thierry Douez - http://sunny-tdz.com
sunnYrex - sunnYtext2speech - sunnYperl - sunnYmidi - sunnYmage
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: File exists

Richmond Mathewson-2
In reply to this post by JB
Naively I tried this in a button:

on mouseUp
    if exists(file "HereWeGo.txt") then
       open file "HereWeGo.txt" for write
    else
       put "no such file"
       end if
end mouseUp

AND the thing didn't work because 'exists' only works for objects within
Livecode.

BUT this seems a reasonable way to check for a file's existence:

on mouseUp
       read from file "HereWeGo.txt" for 1 line
       if it is empty then
          put "no such file"
          end if
end mouseUp

Richmond.

On 2.04.2016 11:48, JB wrote:

> If I open a file for read or write and the file does
> not exist it will be created.  Is there a way to see
> if the file exists before opening it?  I do not want
> a file to be created if it does not exist.  I guess I
> could check the creation date and if it was just
> created then delete it but I was wondering if there
> is a better way.
>
> JB
>
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
JB
Reply | Threaded
Open this post in threaded view
|

Re: File exists

JB
In reply to this post by Thierry Douez
I LIKE THAT!

thank you very much.

JB



> On Apr 2, 2016, at 2:00 AM, Thierry Douez <[hidden email]> wrote:
>
> Hi,
>
> there is a file ".."
>
> HTH,
>
> Thierry
>
>
> 2016-04-02 10:48 GMT+02:00 JB <[hidden email]>:
>
>> If I open a file for read or write and the file does
>> not exist it will be created.  Is there a way to see
>> if the file exists before opening it?  I do not want
>> a file to be created if it does not exist.  I guess I
>> could check the creation date and if it was just
>> created then delete it but I was wondering if there
>> is a better way.
>>
>> JB
>>
> --
> ------------------------------------------------
> Thierry Douez - http://sunny-tdz.com
> sunnYrex - sunnYtext2speech - sunnYperl - sunnYmidi - sunnYmage
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
JB
Reply | Threaded
Open this post in threaded view
|

Re: File exists

JB
In reply to this post by Richmond Mathewson-2
Thank you, Richmond!
Your help is always appreciated.

JB



> On Apr 2, 2016, at 2:03 AM, RM <[hidden email]> wrote:
>
> Richmond.

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: File exists

Kay C Lan
In reply to this post by JB
On Sat, Apr 2, 2016 at 4:48 PM, JB <[hidden email]> 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.

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: File exists

Richmond Mathewson-2


On 2.04.2016 20:53, Kay C Lan wrote:

> On Sat, Apr 2, 2016 at 4:48 PM, JB <[hidden email]> 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
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
JB
Reply | Threaded
Open this post in threaded view
|

Re: File exists

JB
In reply to this post by Kay C Lan
Thanks for the code and info, Kay.

JB



> On Apr 2, 2016, at 10:53 AM, Kay C Lan <[hidden email]> wrote:
>
> On Sat, Apr 2, 2016 at 4:48 PM, JB <[hidden email]> 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.
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


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