Solved

find the number of files in a directory? -

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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