查找某个目录下以特定字母开头的文件,不包括子目录,如以test开头
怎么作,要高效

解决方案 »

  1.   

     CFileFind fs;
     bool b=fs.FindFile("C:\\test*");
    while (b)
    {
       b= fs.FindNextFile();
       if ( !fs.IsDirectory() && !fs.IsDots() )
       {
        //处理
    }
    }
      

  2.   


    CStringArray strarray;
    GetFiles( _T("c:\\test*.*", strarray );
    HRESULT GetFiles(const CString& strWildcard, CStringArray& strArrayFiles )
    {
    HRESULT hr = E_FAIL;

    CFileFind finder; // build a string with wildcards
    BOOL bWorking = finder.FindFile(strWildcard); while (bWorking)
    {
    bWorking = finder.FindNextFile(); // skip . and .. files; otherwise, we'd
    // recur infinitely! if (finder.IsDirectory())
    {
    continue;
    } strArrayFiles.Add( finder.GetFilePath() );
    // if it's a directory, recursively search it
    } finder.Close(); return S_OK;
    }
      

  3.   

    FindFirstFile
    FindNextFile用上面的两个API吧。
    在参数的WIN32_FIND_DATA结构体中应该可以实现楼主说的那些规则。
      

  4.   


    void GetFileList(CString path,CString token,CStringArray &files)
    {
       CFileFind finder;   CString strWildcard;
       strWildcard =path+ _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()||finder.IsDirectory())
             continue;      CString fileName=finder.GetFileName();
          if(fileName.Find(token)!=-1)
          {
     files.Add(fileName);
          }   }   finder.Close();
    }