Using 7-Zip from Delphi?
Asked Answered
B

7

27

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?

Belostok answered 16/9, 2008 at 16:57 Comment(0)
F
31

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.

Facula answered 17/9, 2008 at 10:39 Comment(0)
C
26

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;
Complaisant answered 16/9, 2008 at 16:57 Comment(0)
D
6

7 Zip Plugin API

http://www.progdigy.com/?page_id=13

Dorotea answered 16/9, 2008 at 16:57 Comment(0)
H
4

Zip and 7z with NO DLL, try out Synopse: http://synopse.info/forum/viewtopic.php?pid=163

Hower answered 16/9, 2008 at 16:57 Comment(1)
It doesn't look like Synopse supports 7zip, just zip.Skatole
F
3

Delphi now has native, cross platform zip support with TZipFile in XE2:

How to extract zip files with TZipFile in Delphi XE2 and FireMonkey

Fluorinate answered 16/9, 2008 at 16:57 Comment(2)
The link is dead. But this, maybe, can help. docwiki.embarcadero.com/Libraries/XE2/en/System.Zip.TZipFileFaerie
This does not support LZMA compressed archivesArmbruster
B
1

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.

Bugle answered 18/9, 2008 at 11:8 Comment(1)
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.Aviary
J
0

I tried many solutions and had problems, this one worked.

Download https://github.com/zedalaye/d7zip Copy 7z.dll and sevenzip.pas to your project diroctory and add sevenzip.pas to your project.

Then you can use this to unzip:

using sevenzip;

procedure Unzip7zFile (zipFullFname:string);
  var
    outDir:string;
  begin
    with CreateInArchive(CLSID_CFormat7z) do
    begin  
      OpenFile(zipFullFname);
      outDir := ChangeFileExt(zipFullFname, '');
      ForceDirectories (outDir);
      ExtractTo(outDir);
    end;
  end;

Usage:

Unzip7zFile(ExtractFilePath(Application.ExeName) + 'STR_SI_FULL_1000420.7z');
Junette answered 16/9, 2008 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.