2

How to traverse a directory and its sub directories in Inno Setup Pascal scripting? I can not find any method and interface in Inno Setup Help Document.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Sung Qee
  • 335
  • 4
  • 17

1 Answers1

3

Use FindFirst and FindNext support functions.

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;

For examples of use, see:

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992