A: Search for files under the folder BOOL findallfiles (CString szdir) { CFileFind FF; CString FilePath; CString FileName;
if (Szdir.right (1)!= "//") Szdir + = "//";
Szdir + = "*.*";
BOOL res = ff. FindFile (Szdir); while (RES) { res = ff. FindNextFile (); FilePath = ff. GetFilePath (); FileName = ff. GetFileName (); if (!ff. Isdirectory () &&!ff. Isdots ()) {//Isdirectory indicates that this is a directory, isdots indicates that this is. Or ... need to filter out these two if (filename.right (3) = = "MP3" | | filename.right (3) = = "LRC") { do ur things } } } Ff. Close (); return true; } Method Two: Querying the file of a folder int Ifindfiles (char *p_pcpath) { Win32_find_data Findfiledata; HANDLE Hfind; Hfind = FindFirstFile (P_pcpath, &findfiledata); if (Invalid_handle_value = = hfind) { FindClose (hfind); return 0; } FindNextFile (Hfind, &findfiledata); while (1) { Hfind = FindNextFile (Hfind, &findfiledata); if (strcmp (Findfiledata.cfilename, "...")!= 0) { FindClose (hfind); return 1; } } FindClose (hfind); return 0; } Example: Looking for 4 files, one can not be less, one less, even if the search is unsuccessful CFileFind FF; CString FilePath; CString FileName; if (trystrroot. Right (1)!= "//") Trystrroot + = "//"; Trystrroot + = "*.*"; BOOL res = ff. FindFile (Trystrroot); while (RES) { res = ff. FindNextFile (); FilePath = ff. GetFilePath (); FileName = ff. GetFileName (); if (!ff. Isdirectory () &&!ff. Isdots ()) { if (filename.right () = = "Nprg60x5.hex") { J++;//1 } if (Filename.right = = "Partition.mbn") { J++;//2 } if (Filename.right = = "Oemsbl.mbn") { J++;//3 } if (filename.right (8) = = "Amss.mbn") { J++;//4 } } } Ff. Close (); if (j!=4) { MessageBox (_t The path you chose is not correct, please select the right path!), _t ("Path selection Error")); Return } Method Three:BOOL pathfileexists (lpctstr pszpath); Determines if a file exists. ---detected, this function can detect whether a file or directory exists . CString Strtargetfile; CString Strworkpath = getworkpatht ();//Get EXE file path Strtargetfile.format (_t ("%s//ins_list.ini"), Strworkpath)//Get the Ins_list.ini path under this folder If it does not exist, first create if (PathFileExists (strtargetfile)) { DWORD dwattrs = GetFileAttributes (strtargetfile); if (Dwattrs & file_attribute_readonly) { SetFileAttributes (Strtargetfile, Dwattrs &!) FILE_ATTRIBUTE_READONLY); } } |