C++讀取文件夾下的所有文件

讀取文件夾下的所有文件名,並將文件名存放到容器中。 

//獲取文件夾下的所有文件的文件名,並存放到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;
}

得到的容器如果爲空,則說明沒有讀取到文件。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章