Hallo, ich habe es selbst noch nicht ausprobiert aber bin auf diesen code gestossen, vielleicht funktioniert es für nicht-Delphi-11?
stackoverflow.com
Delphi-Quellcode:
type
TZipFileHelper = class helper for TZipFile
procedure Delete(FileName: string);
end;
{ TZipFileHelper }
procedure TZipFileHelper.Delete(FileName: string);
var
i, j: Integer;
StartOffset, EndOffset, Size: UInt32;
Header: TZipHeader;
Buf: TBytes;
begin
i := IndexOf(FileName);
if i <> -1 then begin
// Find extents for existing file in the file stream
StartOffset := Self.FFiles[i].LocalHeaderOffset;
EndOffset := Self.FEndFileData;
for j := 0 to Self.FFiles.Count - 1 do begin
if (Self.FFiles[j].LocalHeaderOffset > StartOffset) and
(Self.FFiles[j].LocalHeaderOffset <= EndOffset) then
EndOffset := Self.FFiles[j].LocalHeaderOffset;
end;
Size := EndOffset - StartOffset;
// Update central directory header data
Self.FFiles.Delete(i);
for j := 0 to Self.FFiles.Count - 1 do begin
Header := Self.FFiles[j];
if Header.LocalHeaderOffset > StartOffset then begin
Header.LocalHeaderOffset := Header.LocalHeaderOffset - Size;
Self.FFiles[j] := Header;
end;
end;
// Remove existing file stream
SetLength(Buf, Self.FEndFileData - EndOffset);
Self.FStream.Position := EndOffset;
if Length(Buf) > 0 then
Self.FStream.Read(Buf[0], Length(Buf));
Self.FStream.Size := StartOffset;
if Length(Buf) > 0 then
Self.FStream.Write(Buf[0], Length(Buf));
Self.FEndFileData := Self.FStream.Position;
end;
end;
Aufruf:
Delphi-Quellcode:
ZipFile.Delete('document.txt');
ZipFile.Add(SS, 'document.txt');
Viel Erfolg!