void CModelDlg::FindBmpFile(CString strFoldername)
{
CString m_cstrFileList=""; 
CFileFind tempFind;  BOOL bFound;
bFound=tempFind.FindFile(strFoldername   +   "\\*.bmp"); 
CString strTmp;  while(bFound) 

bFound=tempFind.FindNextFile();  if(!tempFind.IsDots())
{   
if(tempFind.IsDirectory())

strTmp=""; 
strTmp=tempFind.GetFilePath();
FindBmpFile(strTmp); 

else 

strTmp=tempFind.GetFileName();
strTmp.MakeUpper();                                    if( strTmp.Right(4)==".BMP" ) 

m_cstrFileList+=tempFind.GetFilePath();
m_cstrFileList+=",";



}  tempFind.Close();  return; 
}
只能搜索当前文件夹下面的BMP文件。如果文件夹下面还有文件夹,就不能搜索到下一层的文件夹。为什么呀?怎么修改呢?

解决方案 »

  1.   

    if( strTmp.Right(4)==".BMP" ) 
                    { 
                        m_cstrFileList+=tempFind.GetFilePath();
                        m_cstrFileList+=",";
                    } 
    你这对bmp做了判断了所以只能搜索bmp格式的,这个代码你去晚上搜索下有很多可以直接用的
      

  2.   

    void ffind(char *directory)
    {
    struct _finddata_t ffblk;
    char dirbuf[256];
    char fname[256]; strcpy(dirbuf,directory);
    strcat(dirbuf,"\\*.*");
    long done = _findfirst(dirbuf,&ffblk);
    int find=0;
    while (find==0) 

    if (strcmp(ffblk.name, ".") && strcmp(ffblk.name, ".."))
    {
    strcpy(fname,directory);
    strcat(fname,"\\");
    strcat(fname,ffblk.name); if(isdir(ffblk.name))
    ffind(fname);
    else
    printf("%s\n",fname); 
    }
          find=_findnext(done,&ffblk); 
    }

    _findclose(done);
    }int isdir(char *directory)
    {
    if(strchr(directory,'.'))
    return 0;
    return 1;
    }
      

  3.   

    CFileFind不支持递归调用
    你自己可以实现
      

  4.   

    SearchFolder(CString strFolderName)
    {
      ....
      fileFind.FindFile(strFoldername   +   "\\*.*");
      ...
      if(找到的是目录)  SearchFolder(strFindedFolderName);
      if(找到的内容是BMP文件)
      {
        。
      }
      
    }
      

  5.   

    void CModelDlg::FindBmpFile(CString strFoldername)
    {
        CString m_cstrFileList=""; 
        CFileFind tempFind;     BOOL bFound;
        bFound=tempFind.FindFile(strFoldername   +   "\\*.bmp"); 
        CString strTmp;     while(bFound) 
        { 
            bFound=tempFind.FindNextFile(); 
    //++++++++++++++++++++++++++++++++++++
            if(tempFind.IsDots())
                 continue;   
    //+++++++++++++++++++++++++++++++++++
            if(tempFind.IsDirectory())
             { 
                    strTmp=""; 
                    strTmp=tempFind.GetFilePath();
                    FindBmpFile(strTmp); 
              } 
               else 
                { 
                    strTmp=tempFind.GetFileName();
                    strTmp.MakeUpper();                                                   if( strTmp.Right(4)==".BMP" ) 
                    { 
                        m_cstrFileList+=tempFind.GetFilePath();
                        m_cstrFileList+=",";
                    } 
                } 
           }     tempFind.Close(); 
    }不要把tempFind.IsDirectory()放在if(tempFind.IsDots())它的区域来判断
      

  6.   

    IsDirectory表明这是一个目录,isDots表明这个是.或者..而这两个东西虽然是目录,但是一个表明这个目录本身,一个代表上层目录(但是根目录下面..也是本身)。所以这个表明的意思是finder是一个目录并且不是这个目录本身或者上层目录 。