Displaying a Directory
Use FindFirst() and recursion to display a directory including Subdirectories
procedure TMainForm.Button1Click(Sender: TObject);

  procedure DoFind(A: String; Indent: String);
  var
    Found: Integer;
    SearchRec: TSearchRec;
  begin
    Found := FindFirst(A + '\*.*', faAnyFile, SearchRec);
    while Found = 0 do
      begin
        if SearchRec.Attr = faDirectory then
          begin
            Lb.Items.Add('[' + SearchRec.Name + ']');
            if Length(SearchRec.Name) > 2 then
              DoFind(A + '\' + SearchRec.Name, Indent + ' ');
          end
        else
          Lb.Items.Add(Indent + SearchRec.Name);
        Found := FindNext(SearchRec);
      end;
    FindClose(SearchRec);
  end;

begin
  DoFind('c:\My Documents', ' ');
end;
Notes:
The files are not sorted.
Home