MFC如何打开文件路径

来源:互联网 发布:如何操作淘宝wap访客数 编辑:程序博客网 时间:2024/05/06 00:57

转自:http://linyangmumu.blog.163.com/blog/static/6903134920101024419380/

 

1.void OpenFile()

{

CString m_FileDir;
 BROWSEINFO bi;
 ZeroMemory(&bi, sizeof(BROWSEINFO));
 bi.hwndOwner = m_hWnd;
 bi.ulFlags   = BIF_RETURNONLYFSDIRS;
 LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
 BOOL bRet = FALSE;
 TCHAR szFolder[MAX_PATH*2];
 szFolder[0] = _T('/0');
 if (pidl)
 {
  if (SHGetPathFromIDList(pidl, szFolder)) 
   bRet = TRUE;
  IMalloc *pMalloc = NULL;
  if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc)
  {
   pMalloc->Free(pidl);
   pMalloc->Release();
  }
 }
 m_FileDir = szFolder;   //选择的文件夹路径

}

2.

//查找路径下的文件
 CFileFind  finder;
 CString strWildcard( m_FileDir); //将传入的参数赋于变量 strWildcard
 strWildcard += _T("//*.*");      //构造文件的全路径,类似于 c://aa//*.*
 BOOL bWorking;
 bWorking = finder.FindFile( strWildcard); //开始查找
 while ( bWorking )
 {
  bWorking = finder.FindNextFile();   //如果文件存在,继续查找下一个符合条件的文件
  //跳过"."和".."
  if ( finder.IsDots())
   continue;
  
  CString strName = finder.GetFileName(); //strName就是要找的这个目录下的文件名称
 }

原创粉丝点击