Dear reader. Sometimes we need to get list of file names of a directory. This procedure below will do that for us :
procedure GetFilenames(Path: string; Dest: TStrings);
var
SR: TSearchRec;
begin
if FindFirst(Path+'*.*', faAnyFile, SR) = 0 then
repeat
Dest.Add(SR.Name);
until FindNext(SR) <> 0;
FindClose(SR);
end;
To use that function, for example you need to create a form with a button and listbox, we name it button1 and listbox1. Here is the code to use that procedure
procedure TForm1.Button1Click(Sender: TObject);
var
path:string;
begin
path := 'C:\Movies\';
GetFilenames(path, ListBox1.Items);
end;
Here is the result when we click on button 'Get List Files Name'
|
get list files name in delphi |
No comments:
Post a Comment