System.SysUtils.FindFirst

From RAD Studio API Documentation
Jump to: navigation, search

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

faInvalid

Identifies an invalid file.

faReadOnly

Identifies read-only files or directories.

faHidden

Identifies hidden files or directories.

faSysFile

Identifies system files or directories.

faVolumeID

Deprecated

faDirectory

Identifies a directory.

faArchive

Identifies Windows archived files.

faNormal

Identifies normal files.

faTemporary

Identifies temporary files or directories.

faSymLink

Specifies only symbolic link file types.

faCompressed

Identifies a compressed file or directory.

faEncrypted

Identifies an encrypted file or directory.

faVirtual

Reserved for system use.

faAnyFile

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.

See Also

Code Examples