Copyright: Visual Help Copyright® 1993 Firas Bushnaq


TFileFind Component

Properties

Methods

Description

The TFileFind component easily searches a disk for the first and subsequent occurrences of a specified file.


Properties

SearchDrive

FileName

FoundFile


SearchDrive Property

Description

This property should be loaded with the drive to be searched.  For example, 'c:'.  SearchDrive can alternately specify a starting path such as 'c:\delphi' in which case it will search that directory and all subdirectories beneath 'c:\delphi'.

Example

filefind1.searchdrive := 'c:\delphi\bin';
filefind1.filename := 'readme.txt';
filefind1.filefirst;  {get first occurrence}
if length(filefind1.foundfile) > 0 then  {found one}
....

The above example searches the directory tree starting at 'c:\delphi\bin' for a file 'readme.txt'.


FileName Property

Description

Load this property with the name of the file you are searching for.  This should be the name of the file only, do not include any path information.

Example:

FileFind1.Filename := 'readme.txt';  {this is correct}

FileFind1.Filename := 'c:\readme.txt';  {this is incorrect}


FoundFile

Description

The FoundFile property is run-time only and read only.  If an occurrence of the specified file is found, this property is set to a string which contains the path and filename.

Example:

filefind1.filename := 'readme.txt';
filefind1.searchdrive := 'c:';
filefind1.filefirst; {search for first}
If length(filefind1.foundfile) > 0 then
....  {found one}

The above example searches drive c: for the first occurrence of the file
'readme.txt'.  If the file is found the property foundfile is loaded with the path and filename.  If no occurrence is found, foundfile is an empty string.


Methods

FileFirst

FileNext


FileFirst Method

Description

The FileFirst method searches the SearchDrive for the first occurrence of the file specified in the FileName property.  If an occurrence is found, the FoundFile property is loaded with the path and filename.

See Also:

FileNext

FoundFile Property

Example:

filefind1.searchdrive := 'c:\';
filefind1.filename := 'delphi.exe';
filefind1.filefirst;
while length(filefind1.foundfile) > 0 do
begin
     listbox1.add(filefind1.foundfile);
     filefind1.filenext;
end;

The above example searches drive c: for all occurrences of delphi.exe and adds them to a list box.


FileNext Method

Description

The FileNext method locates any subsequent occurrences of the specified file.  The search continues from the point where the component terminated a prior search using the filefirst or a previous filenext method.

See Also:

FileFirst

Example:

filefind1.searchdrive := 'c:\';
filefind1.filename := 'delphi.exe';
filefind1.filefirst;
while length(filefind1.foundfile) > 0 do
begin
     listbox1.add(filefind1.foundfile);
     filefind1.filenext;
end;

The above example searches drive c: for all occurrences of delphi.exe and adds them to a list box.