Reviewed and revised May 2024
xcall MIAMEX, MX_FINDEND
MX_FINDEND (MIAMEX 23) must be called at the end of each directory scan to release the resources established in the prior call to MX_FINDFIRST. In the case of a nested (or recursive) scan, MX_FINDEND also restores the context so that the next MX_FINDNEXT call will get the next entry in the parent directory. Failure to call MX_FINDEND for each MX_FINDFIRST will eventually lead to a stack overflow.
Following is an example of a single directory scan. See fndirscan.bsi in SOSLIB:[907,010] for a set of functions for performing a nested or recursive directory scan.
Example
xcall MIAMEX, MX_FINDFIRST, directory, status, filename, size, attrib
do while status = 0
....
.. Process directory item here
....
XCALL MIAMEX, MX_FINDNEXT, status, filename, size, attrib
loop
! terminate directory search and free resources
xcall MIAMEX,MX_FINDEND