Solved

Filling a listbox with the names of sub-directories

Posted on 2006-11-03
4
155 Views
Last Modified: 2010-04-05
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.  
0
Comment
Question by:mcmahling
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
TName earned 250 total points
Comment Utility
>I am using Delphi 2006 bds.

.Net or Win32?
If Win32, you might give this a try, it works with D7:


procedure TForm1.ListDirs(const Directory: String; List:TStrings);
var
  SR: TSearchRec;
begin
  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;

procedure TForm1.Button1Click(Sender: TObject);
begin
   ListDirs('C:\',ListBox1.Items);
end;
0
 
LVL 28

Expert Comment

by:TName
Comment Utility
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;
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now