문제
Delphi의 7-Zip DLL을 사용하고 싶지만 적절한 문서나 예제를 찾을 수 없습니다.Delphi의 7-Zip DLL을 사용하는 방법을 아는 사람이 있습니까?
해결책
릴리스 1.102부터 JEDI 코드 라이브러리 에 대한 지원을 가지고 있습니다 7-Zip 에 내장 Jcl압축 단위.하지만 아직 직접 사용해 본 적은 없습니다.
다른 팁
많은 JEDI 코드 라이브러리와 마찬가지로 Oliver Giesen의 답변을 확장하면 괜찮은 문서를 찾을 수 없었지만 이것은 나에게 효과적입니다.
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