Delphi ActiveX
Delphi ActiveX
Iterate over Matching Filenames
See more Zip Examples
Iterates over files within a .zip that match a pattern. In this case, the pattern is "*.pem". This example will open a .zip containing files of type .txt, .cer, .pem, and possibly others, and will iterate over only the .pem files.Chilkat Delphi ActiveX Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
zip: TChilkatZip;
entry: TChilkatZipEntry;
pemStr: WideString;
pattern: WideString;
bHasMoreMatches: Integer;
begin
success := 0;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
zip := TChilkatZip.Create(Self);
// Open a .zip containing PEM files, among other things..
success := zip.OpenZip('qa_data/certs/thawte-roots.zip');
if (success = 0) then
begin
Memo1.Lines.Add(zip.LastErrorText);
Exit;
end;
entry := TChilkatZipEntry.Create(Self);
pattern := '*.pem';
bHasMoreMatches := zip.EntryMatching(pattern,entry.ControlInterface);
while bHasMoreMatches = 1 do
begin
Memo1.Lines.Add('Entry: ' + entry.FileName);
// Get the uncommpressed contents of the entry:
pemStr := entry.UnzipToString(0,'utf-8');
Memo1.Lines.Add(pemStr);
bHasMoreMatches := entry.GetNextMatch(pattern);
end;
end;