Windows API Finefirstfile, FindNextFile

Source: Internet
Author: User

Reference: Https://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspxFindFirstFile

Searches a directory for a file or subdirectory with a name that matches a specific name (or partial name if wildcards is Used).

BOOL WINAPI findnextfile (  _in_  HANDLE            hfindfile,  _out_ lpwin32_find_data lpfindfiledata);
Parameters
lpFileName [In]

The directory or path, and the file name, which can include wildcard characters, for example, an asterisk (*) or a questio N Mark (?).

This parameter should isn't being NULL, an invalid string (for example, an empty string or a string that's missing th e terminating null character), or end in a trailing backslash (\).

If the string ends with a wildcard, period (.), or directory name, the user must has access permissions to the root and a ll subdirectories on the path.

In the ANSI version of this function, the name was limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Lpfindfiledata [out]

A pointer to the WIN32_FIND_DATA structure This receives information about a found file or directory.

Reference: Https://msdn.microsoft.com/en-us/library/windows/desktop/aa364428%28v=vs.85%29.aspx

FindNextFile function

Continues a file search from a previous call to the FindFirstFile, Findfirstfileex, or FindFirstFile Transacted functions.

BOOL WINAPI findnextfile (  _in_  HANDLE            hfindfile,  _out_ lpwin32_find_data lpfindfiledata);
Parameters
hFindFile [In]

The search handle returned by a previous call to the FindFirstFile or Findfirstfileex function.

Lpfindfiledata [out]

A Pointer to the WIN32_FIND_DATA structure This receives information about the found file or subdirectory.

Return value

If The function succeeds, the return value is nonzero and the lpfindfiledata parameter contains information about The next file or directory found.

If The function fails, the return value is zero and the contents of Lpfindfiledata is indeterminate. To get extended error information, call the GetLastError function.

If the function fails because no more matching files can be found, the GetLastError function returns Error_no _more_files.

Reference:

http://www.oschina.net/code/piece_full?code=6095&piece=9712#9712

Traverse Directory:

intSearchstrhead (stringSZCUR2) {    inti =0; Win32_find_data FindData= {0 }; HANDLE Htravsedir=FindFirstFile(Szcur2.c_str (), &FindData); //cout << "First:" << finddata.cfilename << Endl;    if(Htravsedir = =Invalid_handle_value) {cout<< GetLastError () <<Endl; return 0; }     while(FindNextFile(Htravsedir, &FindData)) {        if(strcmp (Finddata.cfilename,".") ==0|| strcmp (Finddata.cfilename,"..") ==0)        {            Continue; }        //cout << i++ << ""; //cout << finddata.cfilename << Endl;        if(Finddata.dwfileattributes &file_attribute_directory) {            stringSZCUR3 =SZCUR2; Szcur3.erase (Szcur3.find_last_of ("*")); //string stemp = ' \ \ ' + (string) finddata.cfilename;SZCUR3 + ="\ "; SZCUR3+=Finddata.cfilename; SZCUR3+="\\*"; Szcur3.erase (Szcur3.find_last_of (" "),1); cout<< SZCUR3 <<Endl;        Searchstrhead (SZCUR3);    }} findclose (Htravsedir); return 0;}

Windows API Finefirstfile, FindNextFile

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.