Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you get number of items in a local folder?

Status
Not open for further replies.

conor0callaghan

Programmer
Mar 18, 2002
20
IE
Hi I've created a CFolderDialog class which is similar to the CFildDialog class. The only difference is that it returns the address of the folder instead of the file..

I want to get create a function which takes in the address of the folder and returns the number of files it contains?
 
use FinfFirstFile/FindNextFile to count the number of files and SetCurrentDirectory to point correctly the path.

Ion Filipski
1c.bmp
 
Here is an example to count the number of files in agiven folder.
int CountFiles(CString & sPath)
{

int iCount = 0;
CFileFind finder;
BOOL bContinue = finder.FindFile(sPath + "\\*.*");
while (bCont)
{
bContinue= finder.FindNextFile();
if(!finder.IsDots())
{
iCount++;

}
}
return icount;
}

/////////////////////////////////////////////////////////
int CountFiles(CString & sPath, CStringArray &arrs;)
{

int iCount = 0;
CStringArray arrs;
CFileFind finder;
BOOL bContinue = finder.FindFile(sPath + "\\*.*");
while (bCont)
{
bContinue= finder.FindNextFile();
if(!finder.IsDots())
{
iCount++;
arrs.Add( finder.GetFileName());
}
}
return icount;
}

Also , depending on your need you can use :
finder.IsDirectory() ,finder.IsHidden() ,finder.IsTemporary() ,finder.IsSystem()

-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top