[Overview][Constants][Types][Classes][Procedures and functions][Variables] Reference for unit 'sysutils' (#rtl)

FindFirst

Start a file search and return a findhandle

Declaration

Source position: filutilh.inc line 86

function FindFirst(

  const Path: String;

  Attr: LongInt;

  out Rslt: TSearchRec

):LongInt;

Description

FindFirstlooks for files that match the name (possibly with wildcards) in Pathand attributes Attr. It then fills up the Rsltrecord with data gathered about the file. It returns 0 if a file matching the specified criteria is found, a nonzero value (-1 on linux) otherwise.

The Rsltrecord can be fed to subsequent calls to FindNext, in order to find other files matching the specifications.

Remark: A FindFirstcall must alwaysbe followed by a FindClosecall with the same Rsltrecord. Failure to do so will result in memory loss.

Errors

On error the function returns -1 on linux, a nonzero error code on Windows.

See also

FindClose

  

Close a find handle

FindNext

  

Find the next entry in a findhandle.

Example

Program Example43;

{ This program demonstrates the FindFirst function }

Uses SysUtils;

Var Info : TSearchRec;
    Count : Longint;

Begin
  Count:=0;
  If FindFirst ('*',faAnyFile and faDirectory,Info)=0 then
    begin
    Repeat
      Inc(Count);
      With Info do
        begin
        If (Attr and faDirectory) = faDirectory then
          Write('Dir : ');
        Writeln (Name:40,Size:15);
        end;
    Until FindNext(info)<>0;
    end;
  FindClose(Info);
  Writeln ('Finished search. Found ',Count,' matches');

End.