Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-02-25
3
Medium Priority
?
280 Views
Last Modified: 2008-02-01
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);
}
//----------------------------------------------
0
Comment
Question by:classobaniera
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
Kocil earned 400 total points
ID: 8017992
The loop is wrong

.....
int ff = FindFirst("c:\\My Surta-Ferta Downloads\\*.*", faAnyFile, sr);

while (ff == 0) {
   ListItem=ListView1->Items->Add();
   ListItem->Caption = sr.Name;
   ff = FindNext(sr);
}
FindClose(sr);
....
0
 

Author Comment

by:classobaniera
ID: 8025070
OK Kocil, now it works fine,thanks so much!
0
 
LVL 5

Expert Comment

by:Kocil
ID: 8040287
Easy fix.
Thanks for the big point :)

0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question