troubleshooting Question

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

Avatar of classobaniera
classobaniera asked on
3 Comments1 Solution293 ViewsLast Modified:
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";

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->Caption = sr.Name;
}while (FindNext(sr) == 0);

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros