Link to home
Start Free TrialLog in
Avatar of mcmahling
mcmahling

asked on

Filling a listbox with the names of sub-directories

I am using Delphi 2006 bds.  I need some code to fill a list box with the paths of the sub-directories given a specified directory.  
ASKER CERTIFIED SOLUTION
Avatar of TName
TName

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TName
TName

Or use IncludeTrailingPathDelimiter if you want to also pass dir paths without trailing backslash:

procedure TForm1.ListDirs(Directory: String; List:TStrings);
var
  SR: TSearchRec;
begin
  Directory:=IncludeTrailingPathDelimiter(Directory);
  if FindFirst(Directory+'*' , faDirectory, SR) = 0 then try
    repeat
      if SR.Attr=faDirectory then
        List.Add(Directory + SR.Name)
    until FindNext(SR) <> 0;
  finally
    FindClose(SR);
  end;
end;