Inno Setup 遍历目录及其子目录

Inno Setup Traverse a directory and its sub directories

如何在 Inno Setup Pascal 脚本中遍历目录及其子目录?我在 Inno Setup 帮助文档中找不到任何方法和接口。

使用FindFirst and FindNext支持函数。

procedure RecurseDirectory(Path: string);
var
  FindRec: TFindRec;
  FilePath: string;
begin
  if FindFirst(Path + '\*', FindRec) then
  begin
    try
      repeat
        if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
        begin
          FilePath := Path + '\' + FindRec.Name;
          if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
          begin
            Log(Format('File %s', [FilePath]));
          end
            else
          begin
            Log(Format('Directory %s', [FilePath]));
            RecurseDirectory(FilePath);
          end;
        end;
      until not FindNext(FindRec);
    finally
      FindClose(FindRec);
    end;
  end
    else
  begin
    Log(Format('Failed to list %s', [Path]));
  end;
end;

使用示例见: