MFC在文件夹目录下找相应文件
已知strPath文件夹目录,找strPath目录下的相应文件路径
void GetFileInPath(CString strPath, std::vector<CString> &vecFilePath) { if (0 == strlen(strPath)) { return; } if (!PathIsDirectory(strPath)) { return; } CString path; path.Format("%s\\*.txt", strPath); //如果想要其他格式文件,把txt换掉即可,我只找txt文件 WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile(path, &FindFileData); while (hFind != INVALID_HANDLE_VALUE) { if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { vecFilePath.push_back(strPath + "\\" + FindFileData.cFileName); } if (!FindNextFile(hFind, &FindFileData)) { FindClose(hFind); hFind = INVALID_HANDLE_VALUE; } } }

浙公网安备 33010602011771号