File occurance check with Abbrevia in Delphi 10.1

255 Views Asked by At

I am trying to check a zip file content(drag and dropped) for a specific file and I am using a method like below;

procedure TForm1.DropTarget1Dropped(Sender: TObject; const Data: TDragObject;
  const Point: TPointF);
  var i:Integer;
begin
AbZipKit1.FileName := Data.Files[0];
if AbZipKit1.FindFile('readme.txt')>0 then showmessage(‘exists’) else
  begin
   showmessage(‘non-exists’);
end;
end;

For that purpose I’ve created 2 zip files and added two txt files (readme.txt and test.txt) in both. But to first file: I’ve added “readme.txt” file first than “test.txt”. To second one I’ve added “test.txt” than “readme.txt”. I mean I’ve changed the order of file adding.

After dropping first file, program shows a message as “exists” but for second file “non-exists”. I think FindFile method search for only first file of zip content. Is there any correct way of searching for a file without caring the order? Thanks.

1

There are 1 best solutions below

2
On BEST ANSWER

FindFile returns the index of the file. Either 0 or 1 for the scenario you describe. So testing >0 is wrong. If the target file is the first in the ZIP container then its index is 0.

An index of -1 is returned when the file is not found. So replace >0 with <> - 1.