讀取文件夾下的所有文件名,並將文件名存放到容器中。
//獲取文件夾下的所有文件的文件名,並存放到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;
}
得到的容器如果爲空,則說明沒有讀取到文件。