C++遍历文件夹的所有文件

来源:互联网 发布:linux 百度云盘同步 编辑:程序博客网 时间:2024/05/20 16:12
void get_all_files_names_within_folder(string folder)
{
vector<string> names;
string search_path = folder + "/*.*";
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile(search_path.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
do {
// read all (real) files in current folder
// , delete '!' read other 2 default folder . and ..
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
names.push_back(fd.cFileName);
}
} while (::FindNextFile(hFind, &fd));
::FindClose(hFind);
}

}

找了好久的C++文件遍历,有的用boost和C++17 filesystem来做,代码非常高效,但是没有安装相应的库,就一直寻找其他方法
这个方法还是容易理解不错。
原创粉丝点击