Click here to Skip to main content
15,884,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All


i want to know that this code return me by doing directory scanning from directory that next file is present am using bool which give me presence of file with signal 1.
i want to write the names of files how

C++
CFileFind find;
      CString path="C:\\TestFile";
      if(path.Right(1) != "\\")
      path += "\\";
      path += "*.txt*";
      BOOL found = find.FindFile(path);
      while (found)
      {
      found = find.FindNextFile();
       // here i need name of file also how to get the name of file
      if(find.IsDots())
          continue;
      }

here

found is bool it scan the directory and run the loop untill files are available

i want to write the names of files also how to do that then i have to use the name of file further

plz help
Posted
Comments
enhzflep 10-May-12 2:17am    
Well, since you are using a an instance of the CFileFind class - 'find', you can msdn CFileName for an explanation of it's member functions. One of these will surely return the name of the current file. - it does! GetFileName(), of all things.. It's a CString that is returned.

You may choose to use a vector of CStrings to hold the list of matching filenames.
i.e
vector<cstring> matchingFiles;
found = find.FindNextFile();
// When you get a CString of the cur filename matching *.txt*, save it
matchingFiles.push_back(found.GetFileName());
Peter_in_2780 10-May-12 2:57am    
That's an answer, not a comment. Promote it
Chuck O'Toole 10-May-12 2:59am    
How can you possibly be using some members of the CFileFind Class (FindFile(), FindNextFile()) without knowing / looking up the other class members? Is this code something you just cut / pasted from the web somewhere? Double-Click on CFileFind (to highlight it) and hit "F1". Read the displayed documentation.

1 solution

Well, since you are using a an instance of the CFileFind class - 'find', you can msdn CFileName for an explanation of it's member functions. One of these will surely return the name of the current file. - it does! GetFileName(), of all things.. It's a CString that is returned.

You may choose to use a vector of CStrings to hold the list of matching filenames.
i.e
vector matchingFiles;
found = find.FindNextFile();
// When you get a CString of the cur filename matching *.txt*, save it
matchingFiles.push_back(found.GetFileName());

And yeah, what Chuck said.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900