$ZSEARCH()

The $ZSEARCH function attempts to locate a file matching the specified file name. If the file exists, it returns the file name; if the file does not exist, it returns the null string.

The format for the $ZSEARCH function is:

$ZSEARCH(expr[,intexpr])

$ZSEARCH() provides a tool for verifying that a file exists. For information to help determine the validity of a file name, see “$ZPARSE()”.

[Note] Note

You can call the POSIX stat() function to access metadata. The optional GT.M POSIX plug-in packages the stat() function for easy access from M application code.

Examples of $ZSEARCH()

Example:

GTM>write $zsearch("data.dat")
/usr/staff/ccc/data.dat
GTM>

This uses $ZSEARCH() to display the full file path name of "data.dat" in the process current default directory.

Example:

GTM>set x=$zsearch("*.c")
GTM>for  set x=$zsearch("*.m") quit:x=""  write !,$zparse(x,"NAME")

This FOR loop uses $ZSEARCH() and $ZPARSE() to display M source file names in the process current working directory. To ensure that the search starts at the beginning, the example resets the context by first searching with a different argument.