?
Solved

CFileFind question

Posted on 1997-12-16
4
Medium Priority
?
704 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
[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
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
anichini earned 210 total points
ID: 1312488
// 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
ID: 1312489
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
ID: 1312490
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
ID: 1312491
sorry my server had a problem sending
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

777 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