1.MFC获取文件夹路径信息
CString GetPath()
{
CString strPath = "";
BROWSEINFO bInfo;
ZeroMemory(&bInfo, sizeof(bInfo));
bInfo.hwndOwner = m_hWnd;
bInfo.lpszTitle = _T("请选择路径: ");
bInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_EDITBOX;
LPITEMIDLIST lpDlist; //用来保存返回信息的IDList
lpDlist = SHBrowseForFolder(&bInfo) ; //显示选择对话框
if(lpDlist != NULL) //用户按了确定按钮
{
TCHAR chPath[MAX_PATH]; //用来存储路径的字符串
SHGetPathFromIDList(lpDlist, chPath);//把项目标识列表转化成字符串
strPath = chPath; //将TCHAR类型的字符串转换为CString类型的字符串
}
return strPath;
}
2.获取文件夹下指定格式的文件,用CListCtrl控件输出其文件名及文件大小
void AddFolder(CString csFolder)
{
if (csFolder[csFolder.GetLength() - 1] != '\\') csFolder += _T("\\");
csFolder += _T("*.*");
CFileFind ff;
BOOL bFind = ff.FindFile(csFolder);
while (bFind)
{