Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List the files of a directory 1

Status
Not open for further replies.

angeloagra

Programmer
May 16, 2003
1
BR
Does anybody know any Delphi command which I can use to get the names of all the files contained by a directory informed as an argument?

Thanks!
 
Lookup the [blue]
Code:
 FindFirst
[/color]
function in the help file and experiment with the provided example.
 
procedure TForm1.ListFileDir(Path: string; FileList: TStrings);
var
SR: TSearchRec;
begin
if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
begin
repeat
if (SR.Attr <> faDirectory) then
begin
FileList.Add(SR.Name);
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ListFileDir('C:\WINDOWS\', ListBox1.Items);
end;

Aaron Taylor
John Mutch Electronics
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top