用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();
}

你可能感兴趣的:(遍历文件夹)