读取文件夹下的所有文件名,并将文件名存放到容器中。
//获取文件夹下的所有文件的文件名,并存放到vector中
std::vector<std::string> getfile(const std::string &path) {
std::vector<std::string> vPath;
intptr_t handle;
struct _finddata_t fileinfo;
handle = _findfirst(path.c_str(), &fileinfo);
if (handle == -1) {
return vPath;
}
do {
vPath.push_back(fileinfo.name);
} while (!_findnext(handle, &fileinfo));
_findclose(handle);
return vPath;
}
得到的容器如果为空,则说明没有读取到文件。