In the forum, beginners often encounter problems that do not know how to traverse files. In fact, it is very easy to use the following code.
Void ChkRecurse (LPCTSTR pstr/* = NULL */) {CFileFind finder; // build a string with wildcards CString strWildcard (pstr); strWildcard + = _ T ("\\*. * "); // start working for files BOOL bWorking = FALSE; try {bWorking = finder. findFile (strWildcard);} catch (CException * e) {char szCause [255] = {0}; e-> GetErrorMessage (szCause, 255 ); log-> LogOutEx (szCause);} while (bWorking) {try {bWorking = finder. FindNextFile (); // skip. and .. files; otherwise, we 'd // recur infinitely! If (finder. isDots ())//'. and '.. 'Continue; if (finder. isSystem () // System File continue; else if (finder. isDirectory () // directory {CString str = finder. getFilePath (); CString str1; GetDirName (str, str1); if (str1.GetLength () = 12 & _ is_num (str1) {ChkRecurse (str ); // callback} else {Sleep (20); continue ;}} else {// check the file // Do your work ...}} catch (CException * e) {char szCause [255] = {0}; e-> GetErrorMessage (szCause, 255); Log-> LogOutEx (szCause);} finder. close ();}
Comments and comments are welcome if you have any questions.