void CFilesView::OnLButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
::SetCurrentDirectory("C:\\");  
 search_file();   

CScrollView::OnLButtonDown(nFlags, point);
}void CFilesView::search_file()
{
  static CFile file("C:\\Documents and Settings\\Administrator\\桌面\\1.txt",CFile::modeWrite);
  static CArchive arc(&file,CArchive::store);
  WIN32_FIND_DATA data;
 
  HANDLE handle=::FindFirstFile("*.*",&data);
  if(INVALID_HANDLE_VALUE!=handle)
  {
  do{
          
  if(data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
  {
  CString string=data.cFileName;
  CFile file;
  file.Open(string,CFile::modeRead);
          CString stringx=file.GetFilePath();
          int base;
 /*while(base=stringx.Find("\"),base!=-1)
  stringx.Insert(base,"\");*/
        if(string!="."&&string!=". .")
  {
 ::SetCurrentDirectory(stringx);
 arc.WriteString((char*)&stringx);
             search_file();   
             ::SetCurrentDirectory(". .");
  }
  }
 
  }while(::FindNextFile(handle,&data));
  ::FindClose(handle);
}}
第一次:第二次:

解决方案 »

  1.   

    if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
      //排除"."与"..", 因为"."代表当前文件夹, ".."代表上一层文件夹
      if (!lstrcmp(fileInfo.cFileName,".") || !lstrcmp(fileInfo.cFileName,".."))
      {
        //Do nothing for "." and ".." folders
      }
       else
       {
        ......  //你的代码
       }}
      

  2.   


    顺便问一下:
    帮我分析下这个:
    do{
               CString string=data.cFileName;
      if(data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
      {
         //判断是一个文件夹
      CFile file;
      file.Open(string,CFile::modeRead);
              CString stringx=file.GetFilePath();
              int base;

      arc.WriteString(string);
      arc.WriteString(CString(" "));
            if(string!="."&&string!=". .")
      {  //这里判断不等于上一层文件夹或当前文件夹什么意思,事实上判断是文件夹可以递归进去,不是就输出。
     ::SetCurrentDirectory(string);

                 search_file();   
                 ::SetCurrentDirectory(". .");
      }
      }
      else
      {
     arc.WriteString(string); 
          arc.WriteString(CString(" "));
      }
      

  3.   

    试试我写的这个递归函数 
    void FindAllFilesInPath(LPCTSTR strPath) 

    HANDLE hFile; 
    WIN32_FIND_DATA fndInfo; 
    char strPathName[MAX_PATH]; 
    memset(strPathName, 0, MAX_PATH); 
    sprintf(strPathName, "%s\\*.*", strPath); 
    hFile = ::FindFirstFile(strPathName, &fndInfo); 
    do 

    if(hFile==INVALID_HANDLE_VALUE) 
    return; 
    else 

    if(fndInfo.cFileName[0]=='.') 
    continue; 
    char strNewName[MAX_PATH]; 
    memset(strNewName, 0, MAX_PATH); 
    sprintf(strNewName, "%s\\%s", strPath, fndInfo.cFileName); 
    //如果是子目录,则递归搜索 
    if(fndInfo.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) 
      FindAllFilesInPath(strNewName); 
    else//如果是文件 
      { 
      自己处理 
      } 


    while( ::FindNextFile(hFile, &fndInfo) ); 
    ::FindClose(hFile); 
    }
      

  4.   


    还是不对:你看我的》void CFilesView::search_file(char strPath[])
    {
      static CFile file("C:\\Documents and Settings\\Administrator\\桌面\\1.txt",CFile::modeWrite);
      static CArchive arc(&file,CArchive::store);
      static char strNewName[100],strNewName1[100];
      WIN32_FIND_DATA data;
      
      sprintf(strNewName1, "%s\\ *.*", strPath);
      HANDLE handle=::FindFirstFile(strNewName1,&data);
      if(INVALID_HANDLE_VALUE!=handle)
      {
      do{
               CString string=data.cFileName;
      if(data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
      {

      CFile file;
      file.Open(string,CFile::modeRead);
              CString stringx=file.GetFilePath();
              int base;

      arc.WriteString(string);
      arc.WriteString(CString(" "));
      sprintf(strNewName, "%s\\%s", strPath, data.cFileName);  
       
            if(string!="."&&string!=". .")
      {
     //::SetCurrentDirectory(string);

                 search_file(strNewName);   
                //::SetCurrentDirectory(". .");
      }
      }
      else
      {
     arc.WriteString(string); 
          arc.WriteString(CString(" "));
      }
     
      }while(::FindNextFile(handle,&data));
      ::FindClose(handle);
    }}void CFilesView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    //::SetCurrentDirectory("G:\\xx\\");  
     search_file("G:\\\\xx\\\\");   

    CScrollView::OnLButtonDown(nFlags, point);
    }