首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法获得TJclUpdateArchive将压缩文件添加到已经存在的存档中

无法获得TJclUpdateArchive将压缩文件添加到已经存在的存档中
EN

Stack Overflow用户
提问于 2015-07-28 22:16:31
回答 1查看 139关注 0票数 1

我一直在与JclCompression库一起工作,试图将一个文件添加到现有的存档中。不幸的是,当在下面的函数中调用archive.compress时,它会删除原始存档,并将其替换为只包含我试图添加的单个压缩文件的存档(使用相同的文件名)。所有原始文件都已被删除。

代码语言:javascript
复制
function TMyCompression.AddZipItems(const archiveFileName: string; const itemsToZip: TList<TMyCompressionItem>): boolean;
var
  archive: TJclUpdateArchive;
  archiveClass: TJclUpdateArchiveClass;
  packedItemName : string;
  i: Integer;
begin
  archiveClass := GetArchiveFormats.FindUpdateFormat(archiveFileName);
  archive := archiveClass.Create(archiveFileName);
  if NOT Assigned(archive) then
    Result := FALSE
  else
    try
      for i := 0 to itemsToZip.Count -1 do
        begin
          packedItemName := RootPath(itemsToZip[i].Name);
          if itemsToZip[i].IsDirectory then
            archive.AddDirectory(packedItemName, itemsToZip[i].Name, true, true)
          else
            archive.AddFile(packedItemName, itemsToZip[i].Name);
        end;
      archive.Compress;
    finally
      archive.Free;
    end;
 end;

有什么方法可以用JclCompression工具来完成这个任务吗?

编辑:

删除了几个不影响代码的内部函数调用。

我尝试过并拒绝的其他Delphi压缩工具:

  • Delphi的内部System.Zip;没有任何类型的进度或反馈的挂钩。
  • TurboPower Abbrevia v5;我用旧的zip32压缩成功地使用了这个工具几十年。但是,我现在需要zip64支持,最近的版本在我尝试过的前两个超过4GB的文件上失败了(我记得这是一个无效的块大小)。这两个文件都可以用7-zip和打开.
  • Shell到使用的内部压缩工具;我让一个6GB的压缩文件在一夜之间运行,当我早上返回时,它仍然报告说还有20个小时。

7-Zip是非常快,允许良好的反馈,并已充分行使和测试。

EN

回答 1

Stack Overflow用户

发布于 2016-12-25 12:41:02

所有原始文件都已被删除。

使用ListFiles方法

代码语言:javascript
复制
procedure ArchivingLog;
var
  file_name,
  archive_name   : string;
  archive        : TJclCompressArchive;
  archive_format : TJclCompressArchiveClass;
begin
  file_name := format('%s\111.log', [GetCurrentDir]);

  if (FileExists(file_name)) then
  begin
    archive_name   := GetCurrentDir + '\111.log.7z';
    archive_format := GetArchiveFormats.FindUpdateFormat(archive_name);

    if archive_format <> nil then
    begin
      archive := archive_format.Create(archive_name);

      if (FileExists(archive_name)) then
        (archive as TJcl7zUpdateArchive).ListFiles; //without this call deletes all previous files in the archive


      (archive as TJcl7zUpdateArchive).AddFile(ExtractFileName(file_name), file_name);

      try
        (archive as TJcl7zUpdateArchive).Compress;
      finally
        FreeAndNil(archive);
      end;
    end;
  end;
end;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31688077

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档