正文

如何遍历文件夹中的所有文件?2006-10-22 14:48:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/12567/19615.html

分享到:

如何遍历文件夹中的所有文件?void CFileTreeDlg::BrowseFile(int CallNum, CString strFile){   CallNum++;   CFileFind ff;   CString szDir = strFile;    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(); int i =0; switch(CallNum) {    case 1:            strHTFir = m_FileTree.InsertItem(strTitle,0,0,NULL);          break;    case 2:     strHTSec = m_FileTree.InsertItem(strTitle,0,0,strHTFir);         break;    case 3:     strHtThi = m_FileTree.InsertItem(strTitle,0,0,strHTSec);                break;    case 4:     strHtFor = m_FileTree.InsertItem(strTitle,0,0,strHtThi);        break;    default:     strHtFif = m_FileTree.InsertItem(strTitle,0,0,strHtFor);     break;      }        BrowseFile(CallNum,strPath);    }    else if(!ff.IsDirectory() && !ff.IsDots())    {      //显示当前访问的文件      CString strPath;      CString strTitle;      strPath = ff.GetFilePath();      strTitle = ff.GetFileTitle();      switch(CallNum)      { case 1:         strRoot = m_FileTree.InsertItem(strTitle,0,0,NULL);  break; case 2:  strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHTFir);  break; case 3:  strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHTSec);     break; case 4:  strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHtThi);  break; case 5:         strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHtFor);  break; default:  strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHtFif);  break;      }    }  }  ff.Close();//关闭}

阅读(2278) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册