我看了下FindFirstFile(), 它传回的好象是传入进去的那个文件.想问一下在不知道文件夹下的任何文件名时,怎么遍历其中所有的文件?
谢谢!

解决方案 »

  1.   

    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  {
       AfxMessageBox(sFilePath);//枚举到的文件名字
      }
     }
     ff.Close();
    }
      

  2.   

    HANDLE g_hFindFile = NULL;
    const char strDir[] = "F:\\files\\";
    char strFileName[MAX_PATH];
    WIN32_FIND_DATAA fd;strcpy( strFileName, strDir );
    strcat( strFileName, "*.*" );
    g_hFindFile = ::FindFirstFile( strFileName, &fd );
    while( FindNextFile( g_hFindFile, &fd ) )
    {
      fd包含文件(或文件夹)属性
    }
      

  3.   

    bobob(PDFViewer2.0 Release拉!) 
    就方法就解决了.
    要是文件层数太多,文件数量过大,小心你的堆栈溢出就行了.
      

  4.   

    参考下面遍历树: HTREEITEM temFatherItem=  m_msgTree.GetRootItem();
    HTREEITEM temChildItem;
    while(temFatherItem)
    {
            temChildItem=m_msgTree.GetChildItem(temFatherItem); 
    if(temChildItem)
    {
        generalNod_T *pNod_T = (generalNod_T *)m_msgTree.GetItemData(temChildItem);
               delete pNod_T;
               pNod_T=NULL;
        while(temChildItem)
    {
            temChildItem=m_msgTree.GetNextSiblingItem(temChildItem);
            if(temChildItem)
    {
                    pNod_T = (generalNod_T *)m_msgTree.GetItemData(temChildItem);
                       delete pNod_T;
                       pNod_T=NULL;
    }
    }
    }

    temFatherItem=m_msgTree.GetNextSiblingItem(temFatherItem);
    }