Solved

find the number of files in a directory? -

Posted on 2004-08-23
5
275 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:vikasgkutty
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 25 total points
ID: 11871572
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 25 total points
ID: 11878352
This should do it
      CFileFind ff;
      CString s(sNewFolder);
      s += "*.*";   //may need \\*.*   depends on contents of sNewFolder
      int i = 0;
      bool bWorking = ff.FindFile(s, 0);
      while(bWorking)
      {
            if(!ff.IsDots() && !ff.IsDirectory())      
                  i++;
            bWorking = ff.FindNextFile();
      }
      ff.Close();
      s.Format("Found %d files", i);
      AfxMessageBox(s);
0
 
LVL 16

Expert Comment

by:kiranvj
ID: 11960509
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 111
Creating an alias to a directory so I can change the directory 'contents' by changing the alias 5 85
has77  challenge 9 72
wordcount challenge 11 107
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now