# MX\_FINDEND
> [HTML Version](mx_findend.htm)
_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\]](https://bitbucket.org/microsabio/soslib/src/master/907010/fndirscan.bsi) 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