How to verify if a file exist in /file

Hello,

How can I check if there exist a file in /file?? For example there exists a txt file called OK.txt

:if ( the file OK exists in /file ) do={ :put “lala” }

How can I write that statement for the script??

Thanks for your help

:if ([:len [/file find name="filename"]]) do={
  :put "file exists";
}

First find all files with a certain filename. The result is an array of pointers to the files that match the criteria. :len then returns the size of that array, meaning the number of elements in the array. If the size is larger than 0, that is a boolean true.

Thanks for the reply Fewi,

I’ve tried it with your code but it returns an error “Conditional is not boolean”, i’ve added a file “fileverify.txt” into /file, and i’ve tried with these two pieces of code

:if ([:len [/file find name="fileverify"]]) do={
  :put "file exists";
}

and also

:if ([:len [/file find name="fileverify.txt"]]) do={
  :put "file exists";
}

I have also tried with

:if ([:len [/file print where name="fileverify.txt"]]) do={
  :put "file exists";
}

but I still have the same error…what could be wrong?

Thanks for your answers
but keeps telling me the same error, it’s like

:if ([:len [/file find name=“fileverify”]] > 0) do={
:put “file exists”;
}

this way worked out!

tks!!

I have some questions. Can i use like this code for a install?

:if ([:len [/file find type="script"]]) do={import .rsc files}

Can anyone help me?
Thank’s for advance

I am not believe that anybody have some problems. Can anyone help me?

Yes, you can use ‘import’ in scripts.

:if Scripts only works fine with numbers