Inno Setup: List all file names in an directory

余生长醉 提交于 2019-12-18 05:04:12

问题


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.


回答1:


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;


来源:https://stackoverflow.com/questions/19808068/inno-setup-list-all-file-names-in-an-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!