Solved

CFileFind question

Posted on 1997-12-16
4
686 Views
Last Modified: 2013-11-19
CFileFind has FindFile()  and FindNextFile() and GetFileName()
member functions. I would like to do

      CFileFind finder;
      finder.FindFile("*.h");
// NEXT GetFileName can not be used since it can be used
// only after callinf FindNextFile().
                      AfxMessageBox(finder.GetFileName(),MB_OK);
      while(finder.FindNextFile())
      {
          AfxMessageBox(finder.GetFileName(),MB_OK);
      }

but how do I get the name of my first wildcard file. so
I cannot call gefiletname if findnextfile is not called before.
I cannot call findnextfile if findfile is not called before.
But I need to get the first filename. Please do not guess
an answer, I need a working answer
0
Comment
Question by:hasmet
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
anichini earned 70 total points
Comment Utility
// this works, I tried it
CFileFind finder;
finder.FindFile("*.h");
// FindFile just initializes the search, but doesn't actually
// iterate over the results. FindNextFile does that.
// so when you call FindNextFile the first time it returns the
// first file found
while(finder.FindNextFile())
{
    AfxMessageBox(finder.GetFileName(),MB_OK);
}
0
 
LVL 1

Author Comment

by:hasmet
Comment Utility
I do not think so, it will give you one less than total # of ".h" files
in the current dir. I believe the only way is to use the mfc help sample
like :
   CFileFind finder;
    BOOL bWorking = finder.FindFile("*.h");
    while (bWorking)
    {
        bWorking = finder.FindNextFile();
        AfxMessageBox(finder.GetFileName(),MB_OK);
    }

you did exactly what I did (I put the first message box to illustrate, it will
give you ASSERTIONS and crash). but thanks for trying
0
 
LVL 1

Author Comment

by:hasmet
Comment Utility
I do not think so, it will give you one less than total # of ".h" files
in the current dir. I believe the only way is to use the mfc help sample
like :
   CFileFind finder;
    BOOL bWorking = finder.FindFile("*.h");
    while (bWorking)
    {
        bWorking = finder.FindNextFile();
        AfxMessageBox(finder.GetFileName(),MB_OK);
    }

you did exactly what I did (I put the first message box to illustrate, it will
give you ASSERTIONS and crash). but thanks for trying
0
 
LVL 1

Author Comment

by:hasmet
Comment Utility
sorry my server had a problem sending
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now