How to get list of directories inside another directory?

100 views
Skip to first unread message

Lin ArcX

unread,
Dec 25, 2021, 9:22:07 AM12/25/21
to innosetup
Hello. I want to write an innosetup function that give me list of directories. but i couldn't find any solution till now. The only sample code that i found is this(that lists all `files` in a directory):

[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:\Agent\', FileListBox.Items);
end;

Valid file attributes are:

Valid file attributes are:

FILE_ATTRIBUTE_READONLY
FILE_ATTRIBUTE_HIDDEN
FILE_ATTRIBUTE_SYSTEM
FILE_ATTRIBUTE_DIRECTORY
FILE_ATTRIBUTE_ARCHIVE
FILE_ATTRIBUTE_DEVICE
FILE_ATTRIBUTE_NORMAL
FILE_ATTRIBUTE_TEMPORARY
FILE_ATTRIBUTE_SPARSE_FILE
FILE_ATTRIBUTE_REPARSE_POINT
FILE_ATTRIBUTE_COMPRESSED
FILE_ATTRIBUTE_OFFLINE
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
FILE_ATTRIBUTE_ENCRYPTED


Do you know any solution for my problem?

Thanks in advance.

Laurent Combémorel

unread,
Dec 27, 2021, 11:15:53 AM12/27/21
to innosetup
Hello

You have it in the sample code !

File attributes are set to 1 when true. So if a directory entry is a file, the attribute  FILE_ATTRIBUTE_DIRECTORY is set to 0, and if it is a directory, it is set to 1...

Change 
 if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
to
 if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 1 then
and the function will provide a directory list instead of a file list...
Reply all
Reply to author
Forward
0 new messages