FindFirst/FindNext Bug

Giganews Newsgroups
Subject: FindFirst/FindNext Bug
Posted by:  Bjorn Mossberg (BMossbe…@Comcast.net)
Date: Tue, 4 Mar 2008

FindFirst and FindNext interprets the mask '*.xyz' as '*.xyz*'

procedure FindFirstNextBug;
var
found: Integer;
aMask: String;
fName: String;
aPath: String;
aList: TStringList;
fsr:  TSearchRec;
begin
aPath := GetCurrentDir;
{Only *.doc files should be found, but *.docx files are also in the list!}
aMask := aPath + '\*.doc';
aList := nil;
found := FindFirst(aMask,faAnyFile XOR faDirectory,fsr);
try
  aList := TStringList.Create;
  while found=0 do begin
  aList.Add(aPath + '\' + fsr.Name);
  found := FindNext(fsr);
  end;
  DisplayStringList(aList); {Use your favorite display method here.}
finally
  SysUtils.FindClose(fsr);
  aList.Free;
end;
end;

Replies