Link to home
Start Free TrialLog in
Avatar of classobaniera
classobaniera

asked on

Can't get filenames of a directory using FindFirst()

Hello everybody.I'm experimenting on how to retrieve the file names of a directory.(using Borland Builder C++)On my form I have a TListView and a TLabel.Everytime I Button1Click i expect to have the file names of the directory "C:\My Surta-Ferta downloads" shown into ListView1 in Report style.But i only get the "File Name" title on the top raw of the report-styled ListView.The file names of the directory do not appear underneath this title...Could somebody help?

Thi is the code:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 TSearchRec sr;

if (!DirectoryExists("c:\\My Surta-Ferta Downloads"))
  {
 if (!CreateDir("C:\\My Surta-Ferta Downloads"))
throw Exception("Cannot create c:\\Surta-ferta directory.");
  }

  ListView1->ViewStyle = vsReport;
  NewColumn = ListView1->Columns->Add();
  NewColumn->Caption = "File Name";

do
{
FindFirst("c:\\My Surta-Ferta Downloads\\", faAnyFile, sr);
//NOTE:I've also tried with
//"c:\\My Surta-Ferta Downloads\\*.*" and with
//"c:\\My Surta-Ferta Downloads"
//but still didn't work

 ListItem=ListView1->Items->Add();
 ListItem->Caption = sr.Name;
}while (FindNext(sr) == 0);
    FindClose(sr);
}
//----------------------------------------------
ASKER CERTIFIED SOLUTION
Avatar of Kocil
Kocil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of classobaniera
classobaniera

ASKER

OK Kocil, now it works fine,thanks so much!
Easy fix.
Thanks for the big point :)