使用Delphi的7-Zip ?

我想使用Delphi的7-Zip dll,但没有找到像样的文档或示例。有人知道如何使用Delphi中的7-Zip dll吗?

请先 登录 后评论

4 个回答

Oliver Giesen

在1.102版本中,绝地代码库已经支持7-Zip内置到JclCompression单元中。不过我自己还没用过。

请先 登录 后评论
Drejc

如果您打算只使用7Zip进行压缩和解压缩,请查看TZip组件。我为自己的目的编写了一个小的包装程序,您可以在zip中找到它。Pas文件,请随意重用。

请先 登录 后评论
jasonpenny

扩展Oliver Giesen的回答,就像许多JEDI代码库一样,我找不到任何像样的文档,但这对我来说是可行的:

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;
请先 登录 后评论
Hugues Van Landeghem
请先 登录 后评论
  • 26 关注
  • 0 收藏,190 浏览
  • Lawrence Barsanti 提出于 2022-12-17 18:43