c++ 遍历文件夹函数

来源:互联网 发布:ubuntu内核 编辑:程序博客网 时间:2024/06/18 17:15
void getFilesAll(string path, vector<string>& files) {
//文件句柄
intptr_t 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));
getFilesAll(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);
}
}
原创粉丝点击