The function NewFileSearch has been introduced to facilitate searching for files in the file system.

The function returns a TFloFileSearch object which can be used to obtain or process a list of files matching the parameters entered. These parameters are not case sensitive. Please also see TFloFileSearch Class for additional details.

The aPath parameterexpects a full sub-directory path name, with no trailing back-slash (\) - such as C:\Test and not C:\Test\.

The aFileSpec parameter will accept either the full file name, or a wildcard sequence - either TheDummy.txt or *.txt will be accepted.

The aAttr parameter expects a valid value. Please refer to File Attribute for more details regards the file attribute values.

Declaration:      Function NewFileSearch(const aPath, aFileSpec: String; const aAttr: Integer): TFloFileSearch

A full example of the use of this function, with some of its properties and methods in use, is below.

procedure ScriptEvent (var Value : variant);
var
// vi: Integer;
vsearch: TFloFileSearch;
vfiles: TStringList;
begin
LogInfo('');
vfiles := TStringList.Create; //Create empty TStringList
try
vsearch := NewFileSearch('c:\documents', '*.txt', faAnyFile); //Find all text files in c:\documents
try
//Get complete list of matching files into files string list for later processing
vsearch.GetFileNames(vfiles);
 
//Search is automatically reset. We can now list file names and sizes without having to create
//a new search.
//Since the search is reset and reperformed, the list here will be different of matching files
//have been created or deleted since we called GetFileNames().
 
while NOT vsearch.EOF do
begin
LogInfo(vsearch.FileName + ' is ' + IntToStr(vsearch.FileSize) + ' bytes in size');
vsearch.Next;
end;
except
LogInfo('Exception: '+ExceptionToString(ExceptionType, ExceptionParam));
finally
vsearch.Free;
end;
except
LogInfo('Exception: '+ExceptionToString(ExceptionType, ExceptionParam));
 
//The files list still contains the list of filenames we obtained, should we wish to do any processing here,
//even though the file search object has been destroyed and can no longer be used to get file information.
//For the moment, these 2 lines are commented out.
//for i := 0 to Pred(vfiles.Count) do
//LogInfo(vfiles[i]);
 
finally
vfiles.Free;
end;
LogInfo('');
LogInfo('The end!!');
LogInfo('');
end;