MFC打开文件夹,获取非文件夹绝对路径信息
void CfileopDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
// 选择文件夹
CString strFolderPath(_T(""));
TCHAR szPath[_MAX_PATH];
BROWSEINFO bi;
bi.hwndOwner = GetSafeHwnd();
bi.pidlRoot = NULL;
bi.lpszTitle = _T("选择文件夹");
bi.pszDisplayName = szPath;
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = NULL;
LPITEMIDLIST pItemIDList = SHBrowseForFolder(&bi);//这里默认是调用这个函数的父框架
if (pItemIDList)//如果有值
{
if (SHGetPathFromIDList(pItemIDList, szPath))//将IDPI转化为文件路径
{
strFolderPath = szPath;//赋值
//MessageBox(strFolderPath);
}
}
CFileFind finder;
CString sPath(strFolderPath);
sPath += _T("\\*.*");
BOOL bWorking = finder.FindFile(sPath);//找文件夹里面的文件
while (bWorking)
{
bWorking = finder.FindNextFile();
// 跳过 . 和 .. ; 否则会陷入无限循环中!!!
if (finder.IsDots())
continue;
// 如果是目录,进入搜索 (递归ing)!!!
if (!finder.IsDirectory())//不是目录(比如说图片)!!对文件夹有要求!!
{
CString str = finder.GetFilePath();
MessageBox(str);
/*CString str = finder.GetFilePath();
TRACE(_T("%s\n"), (LPCTSTR)str);
Recurse(str);*/
}
}
finder.Close();
}