Solved

CFileFind question

Posted on 1997-12-16
4
697 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 117
move a line in eclipse 3 107
pre4 challenge 19 104
Trying to run powershell  in a batch file. How do I do this? 8 105
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

861 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