博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Windows API 之 FineFirstFile、FindNextFile
阅读量:4921 次
发布时间:2019-06-11

本文共 3065 字,大约阅读时间需要 10 分钟。

参考:

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 .

lpFindFileData [out]

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

参考:

FindNextFile function

Continues a file search from a previous call to the , , or 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 or function.

lpFindFileData [out]

A pointer to the 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 function.

If the function fails because no more matching files can be found, the function returns ERROR_NO_MORE_FILES.

参考:

遍历目录:

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;}

 

转载于:https://www.cnblogs.com/predator-wang/p/4832194.html

你可能感兴趣的文章
MySQL 5.7.14 net start mysql 服务无法启动
查看>>
python重要资源
查看>>
SSRS 传多值参数问题
查看>>
linux快速进入全屏命令行模式
查看>>
colinux安装fedora
查看>>
Moya/RxSwift/ObjectMapper/Alamofire开发
查看>>
有关metric learning
查看>>
java udp 发送小数数字(较难)
查看>>
Caching Tutorial
查看>>
技能的十一个级别
查看>>
织梦简单的自定义表单字段
查看>>
Python的RotatingFileHandler的Bug
查看>>
unity 基础之PhysicsManager
查看>>
printf()详解之终极无惑
查看>>
Common Bugs in C Programming
查看>>
【java面试题】: String类、StringBuffer类、 StringBuilder类的区别
查看>>
各种数据库查询表及表信息的SQL
查看>>
IOS之网络数据下载和JSON解析
查看>>
:Spring-06 -AOP [面向切面编程] -配置异常通知的两种方式--AspectJ 方式 -Schema-based 方式...
查看>>
《网络是怎样连接的》第一章
查看>>