2019-07-28

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

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容