使用FindFirstFile()进行文件遍历,为什么有的目录下的文件或者子目录无法遍历出来
int SearchFile(string path, int* num, map<string, string>* _path)
{
string buffer = "";
buffer = path + "\\*.*";
_WIN32_FIND_DATAA pNextInfo;//保存文件信息
HANDLE hFile = 0;
hFile = FindFirstFileA(buffer.c_str(), &pNextInfo);
int a = GetLastError();
if (a && (a != 2)) {
string errorpath = path+ " : " + to_string(a);
WriteErrorToLog(errorpath);
}
if (hFile != INVALID_HANDLE_VALUE)//
{
do
{
if (pNextInfo.cFileName[0] == '.' || pNextInfo.cFileName[0] == '..')//过滤.和..
continue;
//dwFileAttributes值是可以一位或多位的,不好直接使用"=="来判断
if (pNextInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)//判断是否为文件夹
{
buffer = path + "\\" + pNextInfo.cFileName;//将文件夹追加到目录,成为下一级要搜索目录
SearchFile(buffer, num, _path);//递归
}
ULARGE_INTEGER ulFileSize;
//求得文件的大小
ulFileSize.LowPart = GetCompressedFileSizeA((pNextInfo.cFileName), &(pNextInfo.nFileSizeHigh));
__int64 creattime = *(__int64*)&(pNextInfo.ftCreationTime);//将FILETIME转换成
__int64 writetime = *(__int64*)&(pNextInfo.ftLastWriteTime);
//将文件绝对路径,创建时间,修改时间,文件大小拼接
string str = path + "\\" + pNextInfo.cFileName + to_string(creattime) + to_string(writetime) + to_string(ulFileSize.LowPart);
//遍历结束一个文件路径进行++
//将文件的属性全部存到map中
//求出exe,dll文件
string str_ed = pNextInfo.cFileName;
int size = str_ed.size();
if (size > 3) {
string str_1 = str_ed.substr(size - 3);
//|| strcmp(str_1.c_str(), "exe") == 0
//|| strcmp(str_1.c_str(), "exe") == 0 || strcmp(str_1.c_str(), "bat") == 0
if (strcmp(str_1.c_str(), "dll") == 0) {
string _md5 = md5(str);
buffer = path + "\\" + pNextInfo.cFileName;
(*num)++;
(*_path).insert(pair<string, string>(buffer, _md5));//存储到map中
}
}
} while (FindNextFileA(hFile, &pNextInfo));//遍历文件
}
FindClose(hFile);
return 0;
}

最终遍历出来的文件个数要和everything搜索出来的文件个数要相符合