FindAllFiles function
Returns the list of files in the specified path matching the search criteria.
Declaration
function FindAllFiles(const SearchPath: string;
const SearchMask: string='';
SearchSubDirs: Boolean=True;
DirAttr: Word=faDirectory;
MaskSeparator: char=';'; PathSeparator: char=';')
: TStringList; overloadArguments
SearchPath | Base path for searching files. |
SearchMask | A list of file masks, separated by a semicolon (;), used to determine which files are a match in the routine. The mask can contain wildcards like * and ? and it also supports sets like [a-d,x]. See the Masks unit for more details. The default value is an empty string ('') and causes the all files mask for the platform to be used. |
SearchSubDirs | True to search for matching files in subdirectories. |
DirAttr | Specifies the file attribute which indicates whether a file system entry is
treated as a directory. It can contain
|
MaskSeparator | Separator used between file masks in the SearchMask argument. Default value is ';'. |
PathSeparator | Separator used between path names in the SearchPath argument. Default value is ';'. |
Function result
TStringList instance with the file names matching the search criteria. The StringList is created in the FindAllFiles function; you should not instantiate it before calling the function, and it must be freed in the calling routine.
Description
FindAllFiles is a routine used to gather a list of file names found
in the specified search paths which match the specified file masks. Overloaded
variants are provided which allow the list of matching file names to be
returned in different manners.
The procedure variant uses an existing TStringList class instance to store the matching file names. The function variant creates a new TStringList instance which is used as the return value. It creates the string list internally. This may seem very convenient at first, but it is very easy to create memory leaks if string list instances are not freed properly.
FindAllFiles uses the TListFileSearcher class to perform the file search using the specified parameter values.
See also
Example: fileutil.findallfiles.pas
uses
FileUtil;
var
PascalFiles: TStringList;
begin
PascalFiles := TStringList.Create;
try
FindAllFiles(PascalFiles, LazarusDirectory, '*.pas;*.pp;*.p;*.inc', true); //find e.g. all pascal sourcefiles
ShowMessage(Format('Found %d Pascal source files', [PascalFiles.Count]));
finally
PascalFiles.Free;
end;
end;
// or
begin
//No need to create the stringlist; the function does that for you
PascalFiles := FindAllFiles(LazarusDirectory, '*.pas;*.pp;*.p;*.inc', true); //find e.g. all pascal sourcefiles
try
ShowMessage(Format('Found %d Pascal source files', [PascalFiles.Count]));
finally
PascalFiles.Free;
end;
end;An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
