Keywords
Temporary File wildcard recursive search file folder selection dialog box INI File
Body
Temporary files generated by VC are sometimes really annoying! When you compile a program, a dialog box pops up in the system: "disk D does not have enough space. Do you need to clear the disk?", but it can only clear nkb, do you have any reason not to write a small tool dedicated to clearing VC junk? Run it once every other time to completely clear the specified type of junk files: clean, Chinese, qiqiang!
Obviously, the core code of this program must be a recursive file search function with wildcards. My idea is to first find all the files that meet the conditions under the given directory, and then recursively find all the files that meet the conditions under the lower-level folder. To ensure its closeness, I used a cstringlist & variable to save the search results. If you have good suggestions, please send me an email. The following code is used:
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; }
In addition, two API functions shbrowseforfolder and shgetpathfromidlist are used in the program to open the folder selection dialog box. functions such as getprovateprofileint, get (/write) privateprofilestring, and writeprivateprofilesection are used to help. Because the program is relatively simple, some error information is not abstracted separately. We do not recommend that Readers write like this.