1. Use the most common method on the Internet
Find (char * lppath)
{
Char szfind [max_path];
Win32_find_data findfiledata;
Strcpy (szfind, lppath );
Strcat (szfind ,"*.*");
Handle hfind =: findfirstfile (szfind, & findfiledata );
If (invalid_handle_value = hfind) return;
While (true)
{
If (findfiledata. dwfileattributes & file_attribute_directory)
{
If (findfiledata. cfilename [0]! = '.')
{
Strcpy (szfile, lppath );
Strcat (szfile ,"");
Strcat (szfile, findfiledata. cfilename );
Find (szfile );
}
}
Else
{
Cout <findfiledata. cfilename;
}
If (! Findnextfile (hfind, & findfiledata) break;
}
Findclose (hfind );
}
2. Use the cfilefind class to implement this function more concisely
Void cmodeldlg: findbmpfile (cstring strfoldername) <? XML: namespace prefix = o/>
{
Cstring m_cstrfilelist = "";
Cfilefind tempfind;
Bool bfound; // determines whether the file is successfully found.
Bfound = tempfind. findfile (strfoldername + "\ *. *");/modify the content in "" to specify the file type.
Cstring strtmp; // if the path of the folder is found
While (bfound) // traverse all objects
{
Bfound = tempfind. findnextfile (); // the first execution of findnextfile is to select the first file.
// To the next file
If (! Tempfind. isdots () continue; // if the upper-level directory is returned, the query ends.
If (tempfind. isdirectory () // If a folder is found, the files in the folder are traversed.
{
Strtmp = "";
Strtmp = tempfind. getfilepath ();
Findfile (strtmp );
}
Else
{
Strtmp = tempfind. getfilename (); // save the file name, including the suffix
// Add processing for the found file here
}
}
Tempfind. Close ();
Return;
}