Solved

find the number of files in a directory? -

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

16 Experts available now in Live!

Get 1:1 Help Now