在windows中,使用文件遍历函数_findnext会报0xC0000005错误
原因:
_findnext()第一个参数”路径句柄”,返回的类型为intptr_t(long long),要改为long long或者intptr_t
//获取特定格式的文件名
void GetAllFormatFiles(string path, vector<string>& files, string format)
{
//文件句柄
//long hFile = 0;//会出错
//long long hFile = 0;
intptr_t hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
hFile = _findfirst(p.assign(path).append("\\*" + format).c_str(), &fileinfo);
if (hFile != -1)
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
{
//files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
GetAllFormatFiles(p.assign(path).append("\\").append(fileinfo.name), files, format);
}
}
else
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
int k = _findnext(hFile, &fileinfo);
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}