c++實現Python中listdir

原地址:https://zhuanlan.zhihu.com/p/85094140

#include <iostream>
#include <string>
#include <io.h>
#include<vector>

using namespace std;

void getFiles(string path, vector<string>& files) {
	intptr_t hFile = 0;
	_finddata_t fileinfo;
	if ((hFile = _findfirst(path.append("/*").c_str(), &fileinfo)) != -1) {
		while (_findnext(hFile, &fileinfo) == 0) {
			if (strcmp(fileinfo.name, ".."))
				files.push_back(fileinfo.name);
		}
		_findclose(hFile);
	}
}

int main() {
	string path = "F:\\wzl\\keras_vnet\\2D-Vnet-Keras-master";
	vector<string> files;
	getFiles(path, files);
	for (int i = 0; i < files.size(); i++)
		cout << files[i] << endl;
	getchar();
	return 0;
}

 

發佈了98 篇原創文章 · 獲贊 17 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章