Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use wildcards to compare strings?

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?

like image 819
Jsk Avatar asked Sep 20 '25 17:09

Jsk


1 Answers

Delphi offers unit System.Masks for that. The suitable function here is MatchesMask:

if MatchesMask(sr.Name, '*a.*') then
like image 163
Uwe Raabe Avatar answered Sep 23 '25 11:09

Uwe Raabe