If, then, else Scripting difficulties. Please Help!

:if ( [/file find flash] = yes) do={ certificate import file-name=flash/placeholder passphrase=“placeholder”
certificate import file-name=flash/placeholder passphrase=“placeholder”
certificate import file-name=flash/placeholder passphrase=“placeholder”
certificate import file-name=flash/placeholder passphrase=“placeholder”
certificate import file-name=flash/placeholder passphrase=“placeholder” } else={ certificate import file-name=placeholder passphrase=“placeholder”
certificate import file-name=placeholder passphrase=“placeholder”
certificate import file-name=placeholder passphrase=“placeholder”
certificate import file-name=placeholder passphrase=“placeholder”
certificate import file-name=placeholder passphrase=“placeholder” }

Basically trying to see if the flash folder is there. (This is because older r1 MikroTiks don’t have the flash folder.) and then if it isn’t there go about performing the next set of commands instead. Doing it hilariously wrong atm. Need help getting this right. Any help is much appreciated!

Basically "If flash folder exists; do ‘this set of commands’; else ‘this set of commands’.

any way to get this to work will be much appreciated. (An explanation would be awesome as well!

find gets you an array of results. check if this array’s length is > 0

:if([:len [/file find flash]]>0) do={#stuff}

wiki scripting page is also useful.

It seems to work just fine on R1s (my old script worked on R1s. But on R2s and newer it can’t seem to find the file at all.
Capture2.PNG
Example.PNG

Normally the only safe way to handle things like this in scripting is to use the do { statements } on-error={ statements } construct.
Otherwise when an error occurs during expression evaluation the script simply stops, so you cannot test for conditions like nonexisting items safely.

I got it to work!

:if ( [ :len [ /file find name~"flash" ] ] >0 ) do={ /certificate import file-name=flash/example.crt passphrase="" } else={ /certificate import file-name=example.crt passphrase="" }

Wish I knew this existed before I put an entire day into the previous script. Yes this makes sense. I’ll use this one instead seeing as it works as well and is less likely to do nothing.