Community discussions

MikroTik App
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

How to verify if a file exist in /file

Tue Jul 12, 2011 6:47 pm

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
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: How to verify if a file exist in /file

Tue Jul 12, 2011 7:27 pm

: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.
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

Re: How to verify if a file exist in /file

Tue Jul 12, 2011 7:40 pm

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
 
changeip
Forum Guru
Forum Guru
Posts: 3833
Joined: Fri May 28, 2004 5:22 pm

Re: How to verify if a file exist in /file

Tue Jul 12, 2011 8:44 pm

:if ([:len [/file find name="fileverify"]] > 0) do={
:put "file exists";
}
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

Re: How to verify if a file exist in /file

Wed Jul 13, 2011 6:41 pm

:if ([:len [/file find name="fileverify"]] > 0) do={
:put "file exists";
}
this way worked out!

tks!!
 
nasimjontohirov
just joined
Posts: 4
Joined: Wed Mar 09, 2016 6:48 am

Re: How to verify if a file exist in /file

Fri Apr 01, 2016 6:43 am

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
 
nasimjontohirov
just joined
Posts: 4
Joined: Wed Mar 09, 2016 6:48 am

Re: How to verify if a file exist in /file

Fri Apr 01, 2016 10:50 am

I am not believe that anybody have some problems. Can anyone help me?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7188
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: How to verify if a file exist in /file

Fri Apr 01, 2016 1:26 pm

Yes, you can use 'import' in scripts.
 
PeterDoBrasil
Member Candidate
Member Candidate
Posts: 134
Joined: Sun Aug 23, 2015 6:55 pm

Re: How to verify if a file exist in /file

Mon Apr 04, 2016 5:53 am

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 Scripts only works fine with numbers

Who is online

Users browsing this forum: No registered users and 17 guests