TCHAR szFolderPath[MAX_PATH] = {0};
CString strPath;
BROWSEINFO sInfo;
::ZeroMemory(&sInfo, sizeof(sInfo));
sInfo.pidlRoot = 0;
sInfo.lpszTitle = _T("请读取的文件夹!");
sInfo.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_EDITBOX;
sInfo.ulFlags = NULL;
LPITEMIDLIST lPidBrowse = ::SHBrowseForFolder(&sInfo);//选择文件夹
if (lPidBrowse != nullptr)
{
if (::SHGetPathFromIDList(lPidBrowse, szFolderPath))
{
strPath = szFolderPath;
}
}
if (lPidBrowse != nullptr)
{
::CoTaskMemFree(lPidBrowse);
}
if (strPath.IsEmpty())
{
AfxMessageBox(_T("选择文件夹失败!"));
return;
}
if (!::PathFileExists(strPath))
{
AfxMessageBox(_T("选择文件夹错误!"));
return;
}
strPath += _T("\\*.*");
CFileFind finder;
BOOL bWorking = finder.FindFile(strPath);
std::list<CString> lstName;
CString strText;
while (bWorking)
{
bWorking = finder.FindNextFileW();
if (finder.IsDots())
{
continue;
}
else
{
CString str = finder.GetFileName();
lstName.push_back(str);
strText += str + _T("\r\n");
}
}