Link to home
Start Free TrialLog in
Avatar of hasmet
hasmet

asked on

CFileFind question

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
ASKER CERTIFIED SOLUTION
Avatar of anichini
anichini

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hasmet
hasmet

ASKER

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
Avatar of hasmet

ASKER

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
Avatar of hasmet

ASKER

sorry my server had a problem sending