【发布时间】:2008-09-16 16:57:03
【问题描述】:
我想使用 Delphi 的 7-Zip DLL,但找不到合适的文档或示例。有谁知道如何使用 Delphi 的 7-Zip DLL?
【问题讨论】:
我想使用 Delphi 的 7-Zip DLL,但找不到合适的文档或示例。有谁知道如何使用 Delphi 的 7-Zip DLL?
【问题讨论】:
从 1.102 版开始,JEDI Code Library 支持 7-Zip 内置在 JclCompression 单元中。不过我自己还没用过。
【讨论】:
扩展 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;
【讨论】:
7 Zip 插件 API
【讨论】:
没有 DLL 的 Zip 和 7z,试试 Synopse: http://synopse.info/forum/viewtopic.php?pid=163
【讨论】:
Delphi 现在在 XE2 中使用 TZipFile 提供原生跨平台 zip 支持:
How to extract zip files with TZipFile in Delphi XE2 and FireMonkey
【讨论】:
如果您打算仅将 7Zip 用于 zip 和 unzip,请查看 TZip 组件。 我为自己的目的编写了一个小包装器,您可以在 Zipper.pas 文件中找到它,随时重复使用。
【讨论】:
我尝试了很多解决方案,但都遇到了问题,这个可行。
下载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');
【讨论】: