Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup: List all file names in an directory

Am trying to list all files with names in an directory, but unable to do. Is there any way to list all files with names in an directory?

Thanks in advance.

like image 793
user1752602 Avatar asked Nov 06 '13 09:11

user1752602


1 Answers

The following script shows how to list all files of a specified directory into a TStrings collection (in this example listed in the list box on a custom page):

[Code]
procedure ListFiles(const Directory: string; Files: TStrings);
var
  FindRec: TFindRec;
begin
  Files.Clear;
  if FindFirst(ExpandConstant(Directory + '*'), FindRec) then
  try
    repeat
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
        Files.Add(FindRec.Name);
    until
      not FindNext(FindRec);
  finally
    FindClose(FindRec);
  end;
end;

procedure InitializeWizard;
var
  CustomPage: TWizardPage;
  FileListBox: TNewListBox;
begin
  CustomPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');
  FileListBox := TNewListBox.Create(WizardForm);
  FileListBox.Parent := CustomPage.Surface;
  FileListBox.Align := alClient;

  ListFiles('C:\SomeDirectory\', FileListBox.Items);
end;
like image 89
TLama Avatar answered Oct 17 '22 21:10

TLama