?
Solved

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

Posted on 2003-02-25
3
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

765 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