2008-09-16 94 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');