- 4.74.2.8. -
Table of Contents
4. Standard Units
4.74. WinDos - MS-DOS function emulation for OS/2 and Win32
4.74.2. WinDos Unit Procedures and Functions
4.74.2.8. FindFirst procedure
4.74.2.8. FindFirst procedure
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
WinDos;
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.
- 4.74.2.8. -