Last updated: August 17, 2013 at 18:03 pm

If you need to create a file on a Mikrotik router, but you first want to test if there is a file with that name, here is a little line you can use in a script to check for it.

:if ([:len [/file find name=testfile.txt]] > 0) do={} \
else={/file print file=testfile; :delay 1; /file set testfile.txt contents=""}

Simply, this says:

If a file named ‘testfile.txt‘ is found and its contents have a length greater than zero…
…do nothing…
…else (if there is NOT a file called ‘testfile.txt‘ and it has a length of greater than zero)…
…print this directory’s output** to a file called ‘testfile‘, wait 1 second, then set testfile.txt‘s contents to be blank.

** in Terminal, go to /file.  Type print.  You will see a list of all files on the router.  This is what gets saved into ‘testfile‘ when you do /file print file=testfile.

  • mohammad

    that be very usefull
    thank thank thank aloooooooooot