Link to home
Start Free TrialLog in
Avatar of newuser11
newuser11

asked on

Finding Files


My app is created with vc++ 6.0 win32 with MFC in a shared Dll.

I'm looking for an example code to look for files (ex:c:\test\*.txt -- look for all 'txt' files) and store them in an array and loop through the array.

Thanks.
Avatar of Member_2_1001466
Member_2_1001466

Avatar of newuser11

ASKER

I have tried the CFileFind. Thanks. I have saved the files in a LPCTSTR array. When I tried to loop through, it's not displaying the files. what's wrong with the displaying?

  CFileFind finder;
 LPCTSTR  szFileNames[255];
int i=0;
   BOOL bWorking = finder.FindFile("c:\test\*.txt");

   while (bWorking)
   {
      bWorking = finder.FindNextFile();
     szFileNames[i] =  finder.GetFileName();

      cout << "File Name " << szFileNames[i] << endl;  
     i++;
   }

  for (int j=0; szFileNames[j] != NULL; j++)
  {
      cout << "For Loop " <<  &szFileNames[0] <<  endl;
  }

Thanks.
Increased points
ASKER CERTIFIED SOLUTION
Avatar of wayside
wayside

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