使用Delphi中的7-Zip?

使用Delphi中的7-Zip?,delphi,7zip,Delphi,7zip,我想使用Delphi提供的7-Zip DLL,但没有找到合适的文档或示例。有人知道如何使用Delphi提供的7-Zip DLL吗?从1.102版开始,该单元内置了对的支持。不过,我自己还没有使用过它。如果您打算仅将7Zip用于zip和unzip,请查看该组件。 我为自己的目的编写了一个小包装,您可以在文件中找到,请随意重用。扩展Oliver Giesen的答案,就像许多绝地代码库一样,我找不到任何合适的文档,但这对我来说很有用: uses JclCompression; procedur

我想使用Delphi提供的7-Zip DLL,但没有找到合适的文档或示例。有人知道如何使用Delphi提供的7-Zip DLL吗?

从1.102版开始,该单元内置了对的支持。不过,我自己还没有使用过它。

如果您打算仅将7Zip用于zip和unzip,请查看该组件。
我为自己的目的编写了一个小包装,您可以在文件中找到,请随意重用。

扩展Oliver Giesen的答案,就像许多绝地代码库一样,我找不到任何合适的文档,但这对我来说很有用:

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;
7 Zip插件API


没有DLL的Zip和7z,请试用Synopse:

Delphi现在在XE2中通过TZipFile提供了本机跨平台zip支持:


我尝试了许多解决方案,但都遇到了问题,这一个很有效

下载 将7z.dll和sevenzip.pas复制到项目目录中,并将sevenzip.pas添加到项目中

然后,您可以使用它来解压缩:

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;
用法:

Unzip7zFile(ExtractFilePath(Application.ExeName) + 'STR_SI_FULL_1000420.7z');

如果每个压缩对象都适合内存,TZip就可以正常工作。否则你就有点困难了。尝试制作一个300 mb的拉链,然后用TZip将其中90个300 mb的拉链拉到另一个拉链上,你会有一段有趣的时光。链接已经失效。但这可能会有所帮助。这不支持LZMA压缩文档它看起来不像Synopse支持7zip,只是zip。