压缩所有文件但跳过一个

Tom*_*Tom 1 delphi

我正在压缩具有子目录的目录,并且我不需要的文件很少(在那些子目录中),你可以修改以下脚本以便它会跳过我想要的某些文件吗?

可以为PayPal支付高达20美元的辛苦工作:-)

procedure DoProgress(Sender: TObject; Position, Total: Integer);
procedure DoCompressFile(Sender: TObject; const Filename: string);
Run Code Online (Sandbox Code Playgroud)

....

procedure TJvZLibMultipleMainForm.DoCompressFile(Sender:TObject;const Filename:string);
begin
  lblFilename.Caption := Filename;
  Update;
end;

    procedure TJvZLibMultipleMainForm.btnCompressClick(Sender: TObject);
var
  z : TJvZlibMultiple;
begin
  ForceDirectories(ExtractFilePath(edFilename.Text));
  z := TJvZlibMultiple.Create(nil);
  Screen.Cursor := crHourGlass;
  try
    lblFilename.Caption := '';
    pbProgress.Position := 0;
    z.OnProgress := DoProgress;
    z.OnCompressingFile := DoCompressFile;
    z.CompressDirectory(edSrcFolder.Text,true,edFilename.Text);
  finally
    z.Free;
    Screen.Cursor := crDefault;
  end;
  pbProgress.Position := 0;
  lblFilename.Caption := 'Ready';
end;


procedure TJvZLibMultipleMainForm.DoProgress(Sender: TObject; Position, Total: Integer);
begin
  pbProgress.Max := Total;
  pbProgress.Position := Position;
  Update;
end;
Run Code Online (Sandbox Code Playgroud)

mjv*_*mjv 6

在没有JVCL TJvZlibMultiple组件的真实文档的情况下,对JVCL源代码的回顾表明,在TJvZlibMultiple级别没有可用于防止系统压缩*all*文件(!)的设置目录.看起来甚至无法传递文件过滤器(如"*.PAS").

TJvZlibMultiple对象确实包含一些通知挂钩,例如OnCompressingFile,它在压缩文件之前调用,但驱动逻辑不测试处理程序的任何返回(实际上是一个过程......),因此我们不能使用此设备表示该文件应该是skept.

鉴于这种情况,您有三个主要选择:

  • 由GJ建议,您可以在较低级别工作并提供要单独压缩的文件
    Pseudo code:
       -manually initializing the archive 
       -iterate for each file in the directory (ies) (recursively if needed)
          -decide if file is to be added
          -adding it individually with the TJvZlibMultiple.AddFile() procedure
        -close the archive
        
    简而言之,"没有乐趣":-(这实际上需要从TJvZlibMultiple派生一个类,因为一些过程受到保护,而另一些过程则依赖于一些私有/受保护变量来初始化...
  • 构建了JVCL的自定义版本,特别是对TJvZlibMultiple.pas文件的更改(如果你做得好,可以将其提交回JVCL项目的主干)

    Essentially the Notification events, in particular OnCompressingFile would 
    return a value, either by beying a true function (or a procedure with side
    effect, for backward compatibilty), and such return would be tested by the
    CompressDirectory logic, to skip files (and possibly other features such as
    'abort', 'use an alternate file', whatever...).
  • 预处理目录(ies)

    by [temporarilly] moving the undesired files elsewhere.
    (and then calling the unmodified CompressDirectory(), 
    and then moving the files back...)

实际上,这些解决方案都没有吸引力.恕我直言,中间的可能是最快的,但你的代码将从官方的JVCL分支出来,除非你努力将mod提交给开源项目)

第四种选择可能是使用另一种ZIP库,并以某种方式将其与您的UI集成.

玩得开心 ;-)