質問
Delphi の 7-Zip DLL を使用したいのですが、適切なドキュメントやサンプルが見つかりません。Delphi の 7-Zip DLL の使用方法を知っている人はいますか?
解決
リリース 1.102 以降、 JEDIコードライブラリ のサポートがあります 7-ジップ に組み込まれている Jcl圧縮 ユニット。まだ自分では使っていないのですが。
他のヒント
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 サポートが追加されました。
多くの解決策を試しましたが問題がありましたが、これはうまくいきました。
ダウンロード https://github.com/zedalaye/d7zip7z.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');
所属していません StackOverflow