Windows traverses all files and folders in a folder

Source: Internet
Author: User

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;

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.