您的位置:首页 > 其它

解决Win10下_findnext()异常

2017-06-25 14:39 417 查看
在win10中,使用文件遍历函数_findnext会报0xC0000005错误

原因:

_findnext()第一个参数”路径句柄”,返回的类型为intptr_t(long long),如果定义为long,在win7中是没有问题,但是在win10中就要改为long long或者intptr_t

下面是示例代码:

/* Get all files in a folder specified by path and store the file names in a vector */
void getAllFiles(string path, vector<string> &files) {
long    hFile = 0;
struct _finddata_t fileinfo;
string p;

if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -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));
getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files);
}
}
else {
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}

} while (_findnext(hFile, &fileinfo) == 0);

_findclose(hFile);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: