2008-09-16 98 views

回答

1

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

+0

如果每个压缩对象将装入内存TZip工作正常。否则,你会陷入一片混乱。尝试制作一个300 MB的zip文件,然后将这些300 MB zip文件中的90个zip文件压缩成另一个带有TZip的zip文件,您将有一段有趣的时间。 – 2010-08-25 23:21:29

23

有很多绝地代码库的扩大对奥利弗·吉森的答案,因为,我无法找到任何像样的文档,但是这个工作对我来说:

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; 
0

我尝试了许多解决方案,并有问题,这一个工作。

下载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');