怎么获取文件夹下文件的数目?,只能通过遍历吗?
谢谢!

解决方案 »

  1.   

    int g_nCounter = 0;
    void 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())
    ListFolder(sFilePath);
    }
    else
    {
    g_nCounter++;
    }
    }
    ff.Close();
    }
      

  2.   

    系统你一点右键属性就能看到有多少文件,很快的也是遍历做的吗?
    有没有什么API能直接得到阿
      

  3.   

    只有这一个办法 CFileFind,其实就是封装了API函数
    HANDLE FindFirstFile(
      LPCTSTR lpFileName,
      LPWIN32_FIND_DATA lpFindFileData
    );

    BOOL FindNextFile(
      HANDLE hFindFile,
      LPWIN32_FIND_DATA lpFindFileData
    );
      

  4.   

    while(bFound && g_nCounter>=500)
      

  5.   

    遍历
    CString file = m_strPath + m_strFileNameO + _T( "???") + m_strExtend;
    CFileFind finder;
    int nCount = 0; // file num // contain file name in format : psm21i???.dbf|psm21i???.dbf|
    CString result = _T("");  // get the file name in the variable "result"
    BOOL bExist = finder.FindFile( file ); if( !bExist )
    return; while ( bExist )
    {
    bExist = finder.FindNextFile();
    CString strFileName = finder.GetFileName();
    if( ParseFileName( strFileName ) )
    {
    result += strFileName + "|";
    nCount++;
    }
    } // fill in variable "aryListFileName"
    aryListFileName->SetSize( nCount ); CString strFileName;
    for( int i = 0; i < nCount; i++ )
    {
    int nleft = result.FindOneOf( "|" );
    strFileName = result.Left( nleft ); result = result.Right( result.GetLength() - nleft - 1 ); aryListFileName->SetAt( i, strFileName );
    }