System.SysUtils.FindFirst
Delphi
function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;
C++
extern DELPHI_PACKAGE int __fastcall FindFirst(const System::UnicodeString Path, int Attr, TSearchRec &F);
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | System.SysUtils.pas System.SysUtils.hpp |
System.SysUtils | System.SysUtils |
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 needed information. 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 (on Windows).
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 |
---|---|
Identifies an invalid file. | |
Identifies read-only files or directories. | |
Identifies hidden files or directories. | |
Identifies system files or directories. | |
Deprecated | |
Identifies a directory. | |
Identifies Windows archived files. | |
Identifies normal files. | |
Identifies temporary files or directories. | |
Specifies only symbolic link file types. | |
Identifies a compressed file or directory. | |
Identifies an encrypted file or directory. | |
Reserved for system use. | |
Specifies any file type. |
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 MAC OS.