檔案搜尋演算法(遞迴演算法)

來源:互聯網
上載者:User

 此演算法可以建立樹型列表。

  1. void CFileTreeDlg::AddFile(CString StrPath, HTREEITEM faItem )
  2.     //StrPath為傳遞過來的目錄層次,本次函數調用中搜尋的檔案都是它的下一層的。
  3.     //faItem為傳遞過來的Tree節點,本次函數調用中添加的Tree節點都是它的子節點。
  4. {
  5.  CFileFind OneFile;
  6.  CString FName, DirName;
  7.  BOOL BeWorking; 
  8.  HTREEITEM NewItem; 
  9.  DirName = StrPath+"//*.*";
  10.  BeWorking = OneFile.FindFile( DirName );
  11.  while ( BeWorking ) {    //BeWorking非零,指找了檔案或目錄
  12.   //尋找同級的目錄
  13.   BeWorking = OneFile.FindNextFile();
  14.   if ( OneFile.IsDirectory() && !OneFile.IsDots() )      //如果尋找的結果是目錄又不是".."或"."
  15.   { 
  16.    //向Tree1中添加目錄;
  17.    DirName = OneFile.GetFilePath();
  18.    FName = OneFile.GetFileTitle(); 
  19.    //IDC_TREE1
  20.    NewItem = m_Tree.InsertItem( FName, faItem );    //NewItem取得節點,其目的是為了下一層中
  21.             //添加節點方便,遞迴時把它傳過去。
  22.    //進入下一層遞迴調用。
  23.    AddFile(DirName, NewItem);
  24.   }
  25.   //退出遞迴時,到了這裡!!!
  26.   if ( !OneFile.IsDirectory() && !OneFile.IsDots() )     //如果尋找結果是檔案
  27.   {
  28.    //向Tree1中添加檔案
  29.    FName = OneFile.GetFileTitle();    //注意這裡用的是GetFileTitle,因為
  30.             //這裡是添加檔案。
  31.    m_Tree.InsertItem( FName, faItem );
  32.   }
  33.   
  34.   //BeWorking = OneFile.FindNextFile();
  35.  }// end of while
  36.  OneFile.Close();        //記著用完CFileFild執行個體要關閉
  37. }
  38. GIS導航網

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.