Delphi - how to get a list of all files of directory

Himadri picture Himadri · Jun 12, 2010 · Viewed 80.2k times · Source

I am working with delphi, I want a list of all files of a directory when I execute openpicturedialog.

i.e., When open dialog is executed and i select one file from it, I want the list of all files from the directory of selected file.

You can even suggest me for getting directory name from FileName property of TOpenDialog
Thank You.

Answer

Omair Iqbal picture Omair Iqbal · Jun 12, 2010

if you use delphi 2010 then you can use tdirectory.getfiles first add ioutils.pas to uses clause then write the following line of code in the event handler(in addition to code you already have in that event handler)

uses IOUtils;

 var
    path : string;
begin
    for Path in TDirectory.GetFiles(OpenPictureDialog1.filename)  do
        Listbox1.Items.Add(Path);{assuming OpenPictureDialog1 is the name you gave to your OpenPictureDialog control}
end;