FindFile、FindNextFile做循环。(IsDirectory判断目录)

解决方案 »

  1.   

    http://www.csdn.net/expert/topic/290/290126.xml?temp=.2764246
      

  2.   

    Search()
    {
    CFileFind filetofind;
    filetofind.FindFile()
    while(ret = FiletoFind.FindNextFile())
    {
        ...........
    }
      

  3.   

    void FindFiles(CString pstr)
    {
    CFileFind finder;

    // build a string with wildcards
    CString strWildcard(pstr);
    strWildcard += _T("\\*.*");

    // start working for files
    BOOL bWorking = finder.FindFile(strWildcard);

    while (bWorking)
    {
    bWorking = finder.FindNextFile();
    // skip . and .. files; otherwise, we'd
    // recur infinitely!

    if (finder.IsDots())
    continue;

    // if it's a directory, recursively search it if (finder.IsDirectory())
    {
    CString str = finder.GetFilePath();
    FindFiles(str);
    }
    else
    {
    //在这里添加对所查找文件的处理代码
    // m_file.Add(m_file_);
    if(m_file[m_file_count].Open(finder.GetFilePath(),CFile::modeRead|CFile::modeWrite|CFile::shareExclusive))
    m_file_count++;
    // AfxMessageBox(finder.GetFilePath());
    }
    }

    finder.Close();
    }
      

  4.   

    void EnumFile(CString path)
    {
    CFileFind finder;
    CString str;

    BOOL bWorking=finder.FindFile((LPCTSTR)(path +_T("\\*.*"))); while(bWorking){
    bWorking=finder.FindNextFile();
    str=finder.GetFileName(); if(finder.IsDots()||finder.IsSystem())
    continue; if(finder.IsDirectory())
    EnumFile(path+"\\"+str);
    else
    //got filenames.
    }
    finder.Close();
    }