Inno Setup:在Code部分中递归复制文件夹,子文件夹和文件

Raf*_*LGC 6 inno-setup pascalscript

有没有办法在代码部分中浏览和递归复制/移动目录的所有文件和子目录?(PrepareToInstall)

我需要忽略一个特定的目录,但是使用xcopy它会忽略所有目录/default/,例如,我只需要忽略一个特定的目录.

Files部分在需要时稍后执行.

Mar*_*ryl 11

要以编程方式递归复制目录,请使用:

procedure DirectoryCopy(SourcePath, DestPath: string);
var
  FindRec: TFindRec;
  SourceFilePath: string;
  DestFilePath: string;
begin
  if FindFirst(SourcePath + '\*', FindRec) then
  begin
    try
      repeat
        if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
        begin
          SourceFilePath := SourcePath + '\' + FindRec.Name;
          DestFilePath := DestPath + '\' + FindRec.Name;
          if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
          begin
            if FileCopy(SourceFilePath, DestFilePath, False) then
            begin
              Log(Format('Copied %s to %s', [SourceFilePath, DestFilePath]));
            end
              else
            begin
              Log(Format('Failed to copy %s to %s', [SourceFilePath, DestFilePath]));
            end;
          end
            else
          begin
            if DirExists(DestFilePath) or CreateDir(DestFilePath) then
            begin
              Log(Format('Created %s', [DestFilePath]));
              DirectoryCopy(SourceFilePath, DestFilePath);
            end
              else
            begin
              Log(Format('Failed to create %s', [DestFilePath]));
            end;
          end;
        end;
      until not FindNext(FindRec);
    finally
      FindClose(FindRec);
    end;
  end
    else
  begin
    Log(Format('Failed to list %s', [SourcePath]));
  end;
end;
Run Code Online (Sandbox Code Playgroud)

添加您需要的任何过滤.了解如何过滤...过滤.


有关使用示例,请参阅我对问题的回答: