Windows API 之 FineFirstFile、FindNextFile

來源:互聯網
上載者:User

標籤:

參考: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 are 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 question mark (?).

This parameter should not be NULL, an invalid string (for example, an empty string or a string that is missing the terminating null character), or end in a trailing backslash (\).

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

In the ANSI version of this function, the name is 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 that receives information about a found file or directory.

參考: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 FindFirstFileTransacted 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 that 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 are 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.

參考:

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

遍曆目錄:

int SearchStrHead(string szCur2){    int i = 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)        {            string szCur3 = 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.