Solved

find the number of files in a directory? -

Posted on 2004-08-23
5
279 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 103
zeroMAx challenge 20 114
sumHeights2  challenge 7 117
How to convert MFC::CString to UTF8 wchar_t* 10 292
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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