[Overview][Constants][Types][Procedures and functions][Index] Reference for unit 'amigados' (#aros)

MatchFirst

Finds file that matches pattern

Declaration

Source position: amigados.pas line 2383

function MatchFirst(

  const Pat: STRPTR;

  AP: PAnchorPath

):LongInt;

Arguments

Pat

  

Pattern to search for

AP

  

Place holder for search.

Function result

0 for success or error code.

Description

Locates the first file or directory that matches a given pattern. MatchFirst() is passed your pattern (you do not pass it through ParsePattern() - MatchFirst() does that for you), and the control structure. MatchFirst() normally initializes your AnchorPath structure for you, and returns the first file that matched your pattern, or an error. Note that MatchFirst()/ MatchNext() are unusual for Dos in that they return 0 for success, or the error code, instead of the application getting the error code from IoErr().

When looking at the result of MatchFirst()/ MatchNext(), the ap_Info field of your TAnchorPath has the results of an Examine() of the object. You normally get the name of the object from fib_FileName, and the directory it's in from ap_Current.an_Lock. To access this object, normally you would temporarily CurrentDir() to the lock, do an action to the file/dir, and then CurrentDir() back to your original directory. This makes certain you affect the right object even when two volumes of the same name are in the system. You can use ap_Buf (with ap_StrLen) to get a name to report to the user.

To initialize the TAnchorPath structure (particularily when reusing it), set ap_BreakBits to the signal bits (CDEF) that you want to take a break on, or nil, if you don't want to convenience the user. ap_Flags should be set to any flags you need or all 0's otherwise. ap_FoundBreak should be cleared if you'll be using breaks.

If you want to have the FULL PATH NAME of the files you found, allocate a buffer at the END of this structure, and put the size of it into ap_StrLen. If you don't want the full path name, make sure you set ap_StrLen to zero. In this case, the name of the file, and stats are available in the ap_Info, as per usual.

Then call MatchFirst() and then afterwards, MatchNext() with this structure. You should check the return value each time (see below) and take the appropriate action, ultimately calling MatchEnd() when there are no more files or you are done. You can tell when you are done by checking for the normal AmigaDOS return code ERROR_NO_MORE_ENTRIES.

Note: patterns with trailing slashes may cause MatchFirst()/ MatchNext() to return with an ap_Current.an_Lock on the object, and a filename of the empty string ('').

See ParsePattern() for more information on the patterns.

See also

MatchNext

  

Finds the next file or directory that matches pattern

ParsePattern

  

Create a tokenized string for MatchPattern()

Examine

  

Examine a directory or file associated with a lock

MatchEnd

  

Free storage allocated for MatchFirst()/MatchNext()

ExNext

  

Examine the next entry in a directory


Documentation generated on: 2017-01-10