SysUtils.FindFirst
Contents |
Delphi Information
From SysUtils.pas
function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;
Unit: SysUtils
Type: function
Visibility: public
C++ Information
From SysUtils.hpp
int __fastcall FindFirst(System::UnicodeString Path, int Attr, Sysutils::TSearchRec & F);
Unit: SysUtils
Type: function
Description
Searches for the first instance of a file name with a given set of attributes in a specified directory.
FindFirst searches the directory specified by Path for the first file that matches the file name implied by Path and the attributes specified by the Attr parameter. The result is returned in the F parameter. Use the fields of this search record to extract the information needed. FindFirst returns 0 if a file was successfully located, otherwise, it returns an error code.
The Path constant parameter is the directory and file name mask, including wildcard characters. For example, '.\test\*.*' specifies all files in the test subdirectory.
The Attr parameter specifies the special files to include in addition to all normal files. Choose from these file attribute constants when specifying the Attr parameter.
| Constant | Description |
|---|---|
|
faReadOnly |
Read-only files |
|
faHidden |
Hidden files |
|
faSysFile |
System files |
|
faVolumeID |
Volume ID files |
|
faDirectory |
Directory files |
|
faArchive |
Archive files |
|
faAnyFile |
Any file |
Attributes can be combined by adding (Delphi) or or'ing (C++) their constants or values. For example, to search for read-only and hidden files in addition to normal files, pass (faReadOnly + faHidden) in Delphi or (faReadOnly | faHidden) in C++ as the Attr parameter. To include only normal files, pass zero for the Attr parameter.
Note: FindFirst allocates resources (memory) that must be released by calling FindClose.
Note: Some of the file attribute constants are not valid on all platforms. For example, faVolumeID and faArchive do not work on Linux and Macintosh.
See Also
Code Samples