The RTL code behind GetFiles
calls Masks.MatchesMask
to test for a match to your search pattern. This function only supports masking against a single mask.
The alternative is to use the GetFiles
overload that admits a TFilterPredicate
. You supply a predicate that tests whether or not a name matches your pattern.
uses
StrUtils, Types, Masks, IOUtils;
function MyGetFiles(const Path, Masks: string): TStringDynArray;
var
MaskArray: TStringDynArray;
Predicate: TDirectory.TFilterPredicate;
begin
MaskArray := SplitString(Masks, ';');
Predicate :=
function(const Path: string; const SearchRec: TSearchRec): Boolean
var
Mask: string;
begin
for Mask in MaskArray do
if MatchesMask(SearchRec.Name, Mask) then
exit(True);
exit(False);
end;
Result := TDirectory.GetFiles(Path, Predicate);
end;
Do note that MatchesMask
creates and destroys a heap allocated TMask
every time it is called. I can well imagine that being a performance bottleneck over a long search. In which case you could create an array of TMask
objects from MaskArray
. And use those in the predicate to test. I've no idea whether this is a valid concern or not, just something that occurred to me whilst perusing the code.