Getting a complete directory list off a drive
At the moment I am using the following code to get a directory list. My
problems is that each drive selected will have its own root directories and
the root directories will have their sub directories and so on.
Of course the program isn't going to know this so my question is how do I
get the program to read all subdirectories etc..
Code:
implementation
{$R *.DFM}
{This gets the inital list off drive C}
procedure TForm1.Button1Click(Sender: TObject);
begin
GetDirectories('c:',Memo1);
end;
{This functions retrieves the directories}
procedure GetDirectories(const DirStr : string;
ListBox : TMemo);
var
DirInfo: TSearchRec;
r : Integer;
begin
r := FindFirst(DirStr + '\*.*', FaDirectory, DirInfo);
while r = 0 do begin
Application.ProcessMessages;
if ((DirInfo.Attr and FaDirectory = FaDirectory) and
(DirInfo.Name <> '.') and
(DirInfo.Name <> '..')) then
listbox.lines.Add(DirStr + '\' + DirInfo.Name);
r := FindNext(DirInfo);
end;
FindClose(DirInfo);
end;
{This gets the list from button1 and then finds the first level of
subdirectories}
procedure TForm1.Button2Click(Sender: TObject);
var
counter : integer;
begin
Counter := 0;
while counter < memo1.Lines.Count do
begin
getdirectories(memo1.Lines.Strings[counter],memo2);
inc(counter);
end;
end;
Regards
TimCS