Link to home
Start Free TrialLog in
Avatar of vikasgkutty
vikasgkutty

asked on

find the number of files in a directory? -

Hi,
I have the path of a directory in a CString variable called sNewFolder.
I need to find the total number of files in this directory.
and just messagebox it out.

I think i have to use CFileFind. Any suggetions.
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

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
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

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
hi..

try this
////////////////////////////////////////////////////////
      CFileFind objFile;
      
      int counter = 0 ;
      BOOL bl;
      CString szCounter;
      CString filename;

      ::SetCurrentDirectory(sNewFolder);
      
      bl = objFile.FindFile(NULL,0);
      
      while(bl)
      {
            bl = objFile.FindNextFile();
            if(!(objFile.IsDirectory()))
            {
                  filename = objFile.GetFileName();
                  counter = counter + 1;
                  //AfxMessageBox(filename);
            }
      }
      
      szCounter.Format("Total %d files ",counter);
      AfxMessageBox(szCounter);  

//////////////////////////////////////////

hope this helps
thank u
kiranvj