For example:
Add the file names of all MP3 files in C:/my music to ListBox.
Procedure tform1.button1click (Sender: tobject );
Begin
Createdirtree ('C:/my music /');
End;
Procedure tform1.createdirtree (Path: string );
VaR
SR: tsearchrec;
Found: integer;
Begin
Found: = findfirst (path + '*. *', faanyfile, Sr );
While found = 0 do
Begin
Strtmp: = lowercase (Sr. Name );
If rightstr(strtmp,4){'then
Begin
Listbox1.items. Add (path + Sr. Name );
Createdirtree (path + Sr. Name + '/');
End;
Found: = findnext (SR );
End;
Findclose (SR );
End;
//************************************** ***************************
The following is another method:
function findfile (Path: string): string;
var
REC: tsearchrec;
F: integer;
begin
F: = findfirst (path + '/*. INI ', REC);
while f = 0 DO
begin
If rec. ATTR = 16 then
findfile (path + '/' + rec. name); // call the
else
begin
recursively when the file is a directory... // processing of objects
end;
F: = findnext (REC);
end;
findclose (REC );
end;