void CTestDlg::OnButton1() { CFileDialog mFileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT, "所有文件(*.*)|*.*", NULL/*AfxGetMainWnd()*/); if(mFileDlg.DoModal()==IDOK) { CString strPathName=mFileDlg.GetPathName(); CString strDir = strPathName.Left(strPathName.ReverseFind('\\')); std::vector<CString> vecFile; OnTraverseFolder( strDir,vecFile ); } // 这段是找路径的 } void CTestDlg::OnTraverseFolder(const CString& strDir,std::vector<CString>& vecFile) //这段是读取文件夹内所有文件的 { WIN32_FIND_DATA FindFileData; CString strDirTmp; strDirTmp = strDir; strDirTmp += "\\*.*"; HANDLE hFind=::FindFirstFile(strDirTmp,&FindFileData); if(INVALID_HANDLE_VALUE == hFind) { return; } while(TRUE) { if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if(FindFileData.cFileName[0]!= _T('.')) { strDirTmp = strDir; strDirTmp += "\\"; strDirTmp += FindFileData.cFileName; OnTraverseFolder(strDirTmp,vecFile) ; } } else { strDirTmp = strDir; strDirTmp += "\\"; strDirTmp += FindFileData.cFileName; vecFile.push_back(strDirTmp); } if(!FindNextFile(hFind,&FindFileData)) break; } FindClose(hFind); }