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);
}
//----------------------------------------------
C++

Avatar of undefined
Last Comment
Kocil

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kocil

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
classobaniera

ASKER
OK Kocil, now it works fine,thanks so much!
Kocil

Easy fix.
Thanks for the big point :)

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck