Windows API 之 FineFirstFile、FindNextFile
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Windows API 之 FineFirstFile、FindNextFile,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3284字,纯文字阅读大概需要5分钟。
内容图文
![Windows API 之 FineFirstFile、FindNextFile](/upload/InfoBanner/zyjiaocheng/1113/0ed8eada0e0241f0b533c52bce56115d.jpg)
参考:https://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx
FindFirstFile
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; return0; } 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); return0; }
原文:http://www.cnblogs.com/predator-wang/p/4832194.html
内容总结
以上是互联网集市为您收集整理的Windows API 之 FineFirstFile、FindNextFile全部内容,希望文章能够帮你解决Windows API 之 FineFirstFile、FindNextFile所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。