分类: C/C++
2008-08-01 17:03:34
CStringList& CDelTempDlg::SearchFile(CString strFileName, CString strPath, CStringList &listFileName) { char szFullPathName[MAX_PATH]; /*static*/ WIN32_FIND_DATA findData; SetCurrentDirectory(strPath); HANDLE hFindHandle = FindFirstFile(strFileName, &findData); if ((hFindHandle != INVALID_HANDLE_VALUE)) { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { GetFullPathName(findData.cFileName, MAX_PATH, szFullPathName, NULL); listFileName.AddTail(szFullPathName); } while (FindNextFile(hFindHandle, &findData) != 0) { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { GetFullPathName(findData.cFileName, MAX_PATH, szFullPathName, NULL); listFileName.AddTail(szFullPathName); } } FindClose(hFindHandle); } hFindHandle = FindFirstFile(\"*\", &findData); if ((hFindHandle != INVALID_HANDLE_VALUE)) { if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (findData.cFileName[0] != \''.\'') { SearchFile(strFileName, findData.cFileName, listFileName); SetCurrentDirectory(\"..\"); } } while (FindNextFile(hFindHandle, &findData) != 0) { if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (findData.cFileName[0] != \''.\'') { SearchFile(strFileName, findData.cFileName, listFileName); SetCurrentDirectory(\"..\"); } } } FindClose(hFindHandle); } return listFileName; }另外,程序中还用到了 SHBrowseForFolder、SHGetPathFromIDList 两个API函数来打开文件夹选择的对话框,GetProvateProfileInt、Get(/Write)PrivateProfileString、WritePrivateProfileSection 等函数以方便用户自定义文件类型。因为程序比较简单,里面的一些错误信息显示也就没有单独抽象出来。不提倡读者这样写,呵呵。