Previous: 4.24.2.10. FExpand To the Table of Contents Next: 4.24.2.12. FindNext
4.24.2.10. FExpand Table of Contents 4.24.2.12. FindNext

- 4.24.2.11. -
Table of Contents
4. Standard Units
4.24. DOS - MSDOS support unit
4.24.2. DOS Unit Procedures and Functions
4.24.2.11. FindFirst


4.24.2.11. FindFirst

Targets: MS-DOS, OS/2, Win32


Dos Unit, WinDos Unit

Searches the specified directory for the matching file.

Declaration:
procedure FindFirst(Path: PChar; Attr: Word;
                    var F: TSearchRec);
Remarks:
Path is the drive and directory to search in and the file name to search for. Wildcards are allowed, for instance, 'MYFILE??.*'.

Attr contains the file attributes to include in the search in addition to all normal files.

FindFirst is used in conjunction with FindNext. Use FindNext to locate any addition files matching the search criteria. All errors are reported in DosError, which is a variable defined in the Dos unit.

See also:
FSearch

Example:
program DirList;
uses
  Dos;
var
  TotalDirCnt: Longint;
procedure List(Path : String);
var
  DirSearchRec: SearchRec;
begin
  if (Path[Length(Path)] <> '\') then
    Path := Path + '\';
  FindFirst(Path + '*.*', AnyFile, DirSearchRec);
  while DosError = 0 do
    begin
      if (DirSearchRec.Name <> '.') and
         (DirSearchRec.Name <> '..') and
         ((DirSearchRec.Attr and Directory) <> 0)
         then
        begin
          Inc(TotalDirCnt);
          Writeln(Path + DirSearchRec.Name);
          List(Path + DirSearchRec.Name);
        end;
      FindNext(DirSearchRec);
    end;
  end;
 
begin
  TotalDirCnt := 0;
  List('C:\');
  Writeln;
  Writeln('Total number of directories = ', TotalDirCnt);
end.



Previous: 4.24.2.10. FExpand To the Table of Contents Next: 4.24.2.12. FindNext
4.24.2.10. FExpand Table of Contents 4.24.2.12. FindNext

- 4.24.2.11. -