code_junkie

Using 7-Zip from Delphi?

Nov 10th, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. uses
  2. JclCompression;
  3.  
  4. procedure TfrmSevenZipTest.Button1Click(Sender: TObject);
  5. const
  6. FILENAME = 'F:temptest.zip';
  7. var
  8. archiveclass: TJclDecompressArchiveClass;
  9. archive: TJclDecompressArchive;
  10. item: TJclCompressionItem;
  11. s: String;
  12. i: Integer;
  13. begin
  14. archiveclass := GetArchiveFormats.FindDecompressFormat(FILENAME);
  15.  
  16. if not Assigned(archiveclass) then
  17. raise Exception.Create('Could not determine the Format of ' + FILENAME);
  18.  
  19. archive := archiveclass.Create(FILENAME);
  20. try
  21. if not (archive is TJclSevenZipDecompressArchive) then
  22. raise Exception.Create('This format is not handled by 7z.dll');
  23.  
  24. archive.ListFiles;
  25.  
  26. s := Format('test.zip Item Count: %d'#13#10#13#10, [archive.ItemCount]);
  27.  
  28. for i := 0 to archive.ItemCount - 1 do
  29. begin
  30. item := archive.Items[i];
  31. case item.Kind of
  32. ikFile:
  33. s := s + IntToStr(i+1) + ': ' + item.PackedName + #13#10;
  34. ikDirectory:
  35. s := s + IntToStr(i+1) + ': ' + item.PackedName + ''#13#10;//'
  36. end;
  37. end;
  38.  
  39. if archive.ItemCount > 0 then
  40. begin
  41. // archive.Items[0].Selected := true;
  42. // archive.ExtractSelected('F:temptest');
  43.  
  44. archive.ExtractAll('F:temptest');
  45. end;
  46.  
  47. ShowMessage(s);
  48. finally
  49. archive.Free;
  50. end;
  51. end;
Add Comment
Please, Sign In to add comment