TDirectory.GetFiles has a parameter called SearchPattern. Embarcadero’s documentation says
The mask used when matching file names (for example, “*.exe” matches all the executable files).
However, I want to pass multiple file types. I get those types from a FilterComboBox.Mask. So, it is a string that looks like '*.txt;*.rtf;*.doc'.
I have tried to pass that string directly to GetFiles and it doesn’t work. Do I have to parse it, break it into pieces and feed every individual piece to GetFiles?
The RTL code behind
GetFilescallsMasks.MatchesMaskto test for a match to your search pattern. This function only supports masking against a single mask.The alternative is to use the
GetFilesoverload that admits aTFilterPredicate. You supply a predicate that tests whether or not a name matches your pattern.Do note that
MatchesMaskcreates and destroys a heap allocatedTMaskevery 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 ofTMaskobjects fromMaskArray. 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.