[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

CFileFind question

Posted on 1997-12-16
4
Medium Priority
?
705 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

650 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