I am new at BaseX so please pardon the newbie question.
I am trying to run an xquery script to load a set of xml files in a directory into to BaseX 7.5. 

If I run replace.xq, shown below, it fails with  Out of Main Memory

declare %updating function local:upd($path,$file) {
db:replace("eams",$path,$file)
};
let $files:=for $file in file:list("d:\xmlfiles") return "d:\xmlfiles\"||$file
for $file in $files return local:upd("pd",$file)


But if I run file replace.bxs, it updates with no problem

<commands>
  <replace path="p1">d:\xmlfiles\drr1.xml</replace>
  <replace path="p1">d:\xmlfiles\drr2.xml</replace>
  <replace path="p1">d:\xmlfiles\drr3.xml</replace>
  <replace path="p1">d:\xmlfiles\dw1.xml</replace>
  <replace path="p1">d:\xmlfiles\dlp1.xml</replace>
</commands>

(The same set of files is being processed by both scripts; I checked)

The only idea I have is to use xquery to generate the file replace.bxs and then run it.
A better way?
Thanks.