【问题标题】:Using 7-Zip from Delphi?使用 Delphi 的 7-Zip?
【发布时间】:2008-09-16 16:57:03
【问题描述】:

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

【问题讨论】:

    标签: delphi 7zip


    【解决方案1】:

    从 1.102 版开始,JEDI Code Library 支持 7-Zip 内置在 JclCompression 单元中。不过我自己还没用过。

    【讨论】:

      【解决方案2】:

      扩展 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;
      

      【讨论】:

        【解决方案3】:

        【讨论】:

          【解决方案4】:

          没有 DLL 的 Zip 和 7z,试试 Synopse: http://synopse.info/forum/viewtopic.php?pid=163

          【讨论】:

          • Synopse 好像不支持 7zip,只支持 zip。
          【解决方案5】:

          Delphi 现在在 XE2 中使用 TZipFile 提供原生跨平台 zip 支持:

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

          【讨论】:

          【解决方案6】:

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

          【讨论】:

          • 如果每个压缩对象都适合内存,则 TZip 可以正常工作。否则你会有点紧张。尝试制作一个 300 mb 的 zip,然后使用 TZip 将这 300 mb 的 90 个 zip 压缩到另一个 zip 中,您将度过一段有趣的时光。
          【解决方案7】:

          我尝试了很多解决方案,但都遇到了问题,这个可行。

          下载https://github.com/zedalaye/d7zip 将 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');
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-03-18
            • 2010-12-18
            • 2019-06-18
            • 2016-01-12
            相关资源
            最近更新 更多