tags:

views:

3444

answers:

5

I would like to use the 7-Zip DLLs from Delphi but have not been able to find decent documentation or examples. Does anyone know how to use the 7-Zip DLLs from Delphi?

+3  A: 

This open source component might work for you.

Lars Truijens
+7  A: 

As of release 1.102 the JEDI Code Library has support for 7-Zip built into the JclCompression unit. Haven't used it myself yet, though.

Oliver Giesen
+1  A: 

If you intend to use 7Zip only for zip and unzip take a look at the TZip component. I have written a small wrapper for my own purposes, which you can find in the Zipper.pas file, feel free to reuse.

Drejc
TZip works fine if every compressed object will fit in memory. Otherwise you are in a bit of a pinch. Try to make a 300 mb zip, and then zip 90 of those 300 mb zips into another zip with TZip and you will have an interesting time.
Warren P
+3  A: 

Expanding on Oliver Giesen's answer, as with a lot of the JEDI Code Library, I couldn't find any decent documentation, but this works for me:

uses
   JclCompression;

procedure TfrmSevenZipTest.Button1Click(Sender: TObject);
const
   FILENAME = 'F:\temp\test.zip';
var
   archiveclass: TJclDecompressArchiveClass;
   archive: TJclDecompressArchive;
   item: TJclCompressionItem;
   s: String;
   i: Integer;
begin
   archiveclass := GetArchiveFormats.FindDecompressFormat(FILENAME);

   if not Assigned(archiveclass) then
      raise Exception.Create('Could not determine the Format of ' + FILENAME);

   archive := archiveclass.Create(FILENAME);
   try
      if not (archive is TJclSevenZipDecompressArchive) then
         raise Exception.Create('This format is not handled by 7z.dll');

      archive.ListFiles;

      s := Format('test.zip Item Count: %d'#13#10#13#10, [archive.ItemCount]);

      for i := 0 to archive.ItemCount - 1 do
      begin
         item := archive.Items[i];
         case item.Kind of
            ikFile:
               s := s + IntToStr(i+1) + ': ' + item.PackedName + #13#10;
            ikDirectory:
               s := s + IntToStr(i+1) + ': ' + item.PackedName + '\'#13#10;//'
         end;
      end;

      if archive.ItemCount > 0 then
      begin
//         archive.Items[0].Selected := true;
//         archive.ExtractSelected('F:\temp\test');

         archive.ExtractAll('F:\temp\test');
      end;

      ShowMessage(s);
   finally
      archive.Free;
   end;
end;
jasonpenny
A: 

7 Zip Plugin API

http://www.progdigy.com/?page%5Fid=13

Hugues Van Landeghem