CFileFind实现遍历文件夹,获得文件夹下子文件个数,亲测通过

来源:互联网 发布:原单男装 淘宝店铺 编辑:程序博客网 时间:2024/05/16 11:54

void CCount_fileDlg::OnBnClickedOk()
{
         // TODO: 在此添加控件通知处理程序代码
       CString path = "d:\\Program Files";
       int n = ListFolder(path);
       CString number;
       number.Format("file numbers is:%d",n);
       AfxMessageBox(number);
        //CDialogEx::OnOK();
}
int   g_nCounter   =   0;
int CCount_fileDlg::ListFolder(CString   sPath)

       CFileFind   ff; 
       BOOL   bFound; 
       bFound   =   ff.FindFile(sPath   +   "\\*.* "); 
       while(bFound) 
       { 
              bFound   =   ff.FindNextFile(); 
              CString   sFilePath   =   ff.GetFilePath();

              if(ff.IsDirectory()) 
              { 
                     if(!ff.IsDots()) 
                      CCount_fileDlg::ListFolder(sFilePath); 
              } 
              else 
              { 
                     g_nCounter++; 
              } 
       } 
       //ff.Close(); 
       return g_nCounter;
}

原创粉丝点击