# MX\_FINDNEXT

> [HTML Version](mx_findnext.htm)

_Reviewed and revised May 2024_

**xcall MIAMEX, MX\_FINDNEXT, status, filename, size, attrib \{,cdate, ctime, udate, utime \{, adate, atime\}\}**

MX\_FINDNEXT (MIAMEX 21) returns the next file or subdirectory in the directory specified in MX\_FINDFIRST, which must be called first to initialize this operation.

**Parameters**

The parameters are the same as for MX\_FINDFIRST except that the first parameter, _directory,_ is omitted here since it is maintained internally after being established by the initial MX\_FINDFIRST call.

**Comments**

MX\_FINDNEXT does not automatically descend directory levels; it merely scans the items in the directory initialized by the prior MX\_FINDFIRST. If you want to do a recursive scan, descending levels, you need to execute another MX\_FINDFIRST for each item directory item, as indicated by the _attrib_ parameter.

The return _status_ will be non-zero when you hit the end of the directory—i.e., there are no more files. MX\_FINDEND (which see for an example) must be executed at the end of each directory scan to clear the resources allocated by the MX\_FINDFIRST and, in the case of a nested scan, to pop the status back to the parent directory where you can continue the that scan. 

See [MX\_FINDEND](mx_findend.md) for additional information and a program example, and the History note in [MX\_FINDFIRST](mx_findfirst.md).

**History**

2021 October, A-Shell 6.5.1708:  MX\_FINDFIRST refinement: Overflowing the directory processing stack now generates ASB error 33, stack overflow. Previously it only returned a non-zero status, making it too easy for the calling program to continue running without recognizing the error, leading to incorrect or inconsistent directory scan results. Furthermore, after such an error, the stack was not getting reset, leading to more errors on subsequent multi-level directory scans.

2021 October, A-Shell 6.5.1708:  Extend the maximum number of nesting levels from 3 to 20. This was done years ago for the Windows version but somehow overlooked for the Unix version.

2020 October, A-Shell 6.5.1690:  Expand the limit on the maximum length of a filename from 123 to 255 characters.