Pilot Script to loop through files

I’m trying to convert every .mtx matrix file in a folder into an OMX file so I can use it in other applications. I’m familiar with the CONVERTMAT pilot command, but I’m struggling to use the pilot application to loop through every file. This works, for instance:

CONVERTMAT FROM="directory/file1.mtx" TO="directory/file1.omx"
CONVERTMAT FROM="directory/file2.mtx" TO="directory/file2.omx"

But you can see how tedious this would get after only a few files (and I have like 30), and they might change, etc.) What I want is something like this:

mydir = "directory/"
files = ["file1", "file2"]
loop i = 1, length(files)
   CONVERTMAT FROM="@mydir@/" + files[i] + ".mtx" 
                TO="@mydir@/" + files[i] + ".omx" 
endloop

But I can’t figure out from the documentation how to create an array in pilot (they seem to only be defined in matrix and network), or even how to define arbitrary variables.

Even better would be a dir command like exists in most languages to get every file so I don’t have to create files manually.

At this point, what I think I want most is simply a command-line call to CONVERTMAT so I can do things in some other language.