怎样计算一个文件夹中的文件个数?并且如何逐一取出其文件名?

解决方案 »

  1.   

    下面的代码你也许用的着
    BOOL GetFolderAndFile(CString szFolder)
    { CFileFind finder;
    CString szSearch="";
    szSearch.Format("%s\\*.*", szFolder);
    BOOL bFind=finder.FindFile(szSearch);
    if(!bFind)return FALSE;
    CString szPath="";
    while(bFind){
    bFind=finder.FindNextFile();
    if(finder.IsDots())continue;
    szPath=finder.GetFilePath();
    if(finder.IsDirectory()){
                               cout<<"find a Folder:"<<szPath<<endl;
    GetFolderAndFile(szPath);
    continue;
    }
                      else 
                      {
                           cout<<"Find a File:"<<szPath<<end;
                           //取文件属性
                           ...
                      }

    nSize+=finder.GetLength();
    } finder.Close();
    return TRUE;
    }