FindFirst

Start search for one or more files.

Declaration

Source position: dosh.inc line 104

  procedure FindFirst(const path: PathStr; attr: Word; var f: SearchRec);

Description

FindFirst searches the file specified in Path. Normal files, as well as all special files which have the attributes specified in Attr will be returned.

It returns a SearchRec record for further searching in F. Path can contain the wildcard characters ? (matches any single character) and * (matches 0 ore more arbitrary characters). In this case FindFirst will return the first file which matches the specified criteria. If DosError is different from zero, no file(s) matching the criteria was(were) found.

Remark

On the EMX target, you cannot issue two different FindFirst calls. That is, you must close any previous search operation with FindClose before starting a new one. Failure to do so will end in a Run-Time Error 6 (Invalid file handle) !!!

Errors

Errors are reported in DosError.

See also

Name Description
FindClose Dispose resources allocated by a FindFirst /FindNext sequence.
FindNext Find next matching file after FindFirst

Example

Program Example7;
uses Dos;
{ Program to demonstrate the FindFirst and FindNext function. }
var
  Dir : SearchRec;
begin
  FindFirst('*.*',archive,Dir);
  WriteLn('FileName'+Space(32),'FileSize':9);
  while (DosError=0) do
   begin
     Writeln(Dir.Name+Space(40-Length(Dir.Name)),Dir.Size:9);
     FindNext(Dir);
   end;
  FindClose(Dir);
end.