【发布时间】:2012-10-31 18:21:43
【问题描述】:
我想用 Delphi XE2/XE3 标准 System.Zip 单元替换 zip 存档中的文件(= 删除旧文件并添加新文件)。但是没有替换/删除方法。有没有人知道如何在不需要提取所有文件并将它们添加到新存档的情况下实现它?
我有这段代码,但如果它已经存在,它会再次添加“document.txt”:
var
ZipFile: TZipFile;
SS: TStringStream;
const
ZipDocument = 'E:\document.zip';
begin
ZipFile := TZipFile.Create; //Zipfile: TZipFile
SS := TStringStream.Create('hello');
try
if FileExists(ZipDocument) then
ZipFile.Open(ZipDocument, zmReadWrite)
else
ZipFile.Open(ZipDocument, zmWrite);
ZipFile.Add(SS, 'document.txt');
ZipFile.Close;
finally
SS.Free;
ZipFile.Free;
end;
end;
注意:我以前使用过 TPAbbrevia(完成了这项工作),但我现在想使用 Delphi 的 Zip 单元。所以请不要回答“使用另一个库”之类的问题。谢谢。
【问题讨论】:
-
您已经回答了自己的问题。内置的 ZIP 库不支持该功能。
-
也许有人写了一个hack?
-
你为什么不使用 Abbrevia?有人告诉我,它非常好。
-
我确实使用过它,它很棒。但是我编写了一个需要 zip 功能的库,并且我确实想减少依赖关系。此外,如果您需要 OSX 平台支持,对于没有经验的用户来说,安装 TPAbbrevia 有点棘手。
标签: delphi zip delphi-xe2 delphi-xe3