I have a set of files:
001.txt
001a.txt
002.txt
002a.txt
...
I am trying to use the following code to exclude items ending with a
, such as 001a.txt
PROCEDURE TForm1.FindFiles(StartDir, FileMask: STRING);
VAR
sr: TSearchRec;
IsFound: Boolean;
BEGIN
IsFound := FindFirst(StartDir + FileMask, faAnyFile - faDirectory, sr) = 0;
WHILE IsFound DO
BEGIN
if sr.Name <> '*a.*' then
gFiles.add(StartDir + sr.Name);
IsFound := FindNext(sr) = 0;
END;
FindClose(sr);
END;
The FileMask
being passed to this procedure is '*.*'
to include all files.
However the above returns all files.
So my question is how do I exclude those files from the search?
Delphi offers unit System.Masks
for that. The suitable function here is MatchesMask:
if MatchesMask(sr.Name, '*a.*') then
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With