做一个函数 在磁盘搜索一个文件夹 比如在D盘里想要找一个A文件夹,A文件不知道在哪里,所以一个个搜索,找到的话就赋值给string字段 各位有没有参考的函数 或小例子也可以 在下学了一个月嘿嘿
解决方案 »
- 数据库奇怪问题
- 有关水晶报表的动态链接库craxddrt.dll的导入
- 我在cmainframe中通过GetActiveView()来获得view类指针但为什么。。。。。
- 如何指定系统已经注册窗体类程序的WndProc
- 光标的闪动
- 在线等:关于MSN的图释问题!
- 如何访问EXE程序中的ATL接口?
- 请教一个极弱智的问题:有关Radio Button
- 用数据库的方式读Excel,遇新旧版本Excel文件格式不一致的问题。xls 和 xlsx
- 如何将字符串转化为double类型?
- VC2008怎么嵌入汇编代码
- 关于error C2065: 'CMainFrame' : undeclared identifier问题
{
HRESULT hr = E_FAIL;
DWORD len = (strlen(dir) + 5) * sizeof(TCHAR); LPTSTR tmpDirExpr = new TCHAR[strlen(dir) + 5];
memset(tmpDirExpr, 0, len);
strcat(tmpDirExpr, dir);
strcat(tmpDirExpr,_T("//*")); CFileFind *pfilefind = new CFileFind(); BOOL isResOK = pfilefind->FindFile((LPCTSTR)tmpDirExpr);
while(isResOK)
{
isResOK = pfilefind->FindNextFile();
if(!pfilefind->IsDots())
{
CString foundPathStr = pfilefind->GetFilePath();
if(foundPathStr == filename)
{
DWORD len = (foundPathStr.GetLength() + 1) * sizeof(TCHAR);
memcpy(resultPath,foundPathStr.GetBuffer(), len);
foundPathStr.ReleaseBuffer();
hr = S_OK;
break;
} if(pfilefind->IsDirectory())
{
CString subDir = pfilefind->GetFilePath();
if(SUCCEEDED(FindFile(subDir, filename, resultPath)))
{
hr = S_OK;
break;
}
//free(newSubDir);
}
}
} pfilefind->Close();
delete pfilefind;
delete tmpDirExpr; return hr;
}
char szPath[MAX_PATH]; //存放选择的目录路径
CString str;
ZeroMemory(szPath, sizeof(szPath));
BROWSEINFO bi;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = szPath;
bi.lpszTitle = "请选择需要打包的目录:";
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
//弹出选择目录对话框
LPITEMIDLIST lp = SHBrowseForFolder(&bi);
//目录有效
if(!lp || !SHGetPathFromIDList(lp, szPath))
return;
CFileFind ff;
BOOL bFound;
CString sPath=szPath;
bFound = ff.FindFile(sPath+ "\*.exe ");//找第一个文件 只是找有没有,并不得到第一个文件
while(bFound)//如果找到,继续
{
bFound = ff.FindNextFile(); //
CString sFilePath = ff.GetFilePath();
AfxMessageBox(sFilePath);//枚举到的文件名字
}
ff.Close();