用VC遍历文件夹中的所有文件及文件夹

void CBrowseDlg::BrowseDir( CString strDir, HTREEITEM parent )
{
         CFileFind  ff;
         CString    szDir=strDir;
         HTREEITEM  hSubItem;
 
         if(szDir.Right(1) != "//")
         {
                  szDir += "//";
          }
 
         szDir += "*.*";

         BOOL res = ff.FindFile( szDir );

         while(res)
         {
                  res = ff.FindNextFile();
  
                  if( ff.IsDirectory() && !ff.IsDots() )
                  {
                           CString strPath = ff.GetFilePath();
                           CString strTitle = ff.GetFileTitle();
                           hSubItem = m_fileTree.InsertItem( strTitle, 0, 0, parent );
                           BrowseDir( strPath, hSubItem );
                  }
                  else
                  {
                             if( !ff.IsDirectory() && !ff.IsDots() )
                             {
                                    CString strTitle=ff.GetFileTitle();
                                    m_fileTree.InsertItem( strTitle, 0, 0, parent );
                              }
                      }
           }
 ff.Close();
}

posted on 2012-04-26 18:10  MR赵  阅读(257)  评论(0编辑  收藏  举报

导航