现在的位置: 首页 > 综合 > 正文

读取文件夹下的所有文件

2018年04月01日 ⁄ 综合 ⁄ 共 501字 ⁄ 字号 评论关闭

最近做个项目需要侦听某个文件夹下有无文件,如果有则处理该文件,如果没有继续等待,因此需要读取文件夹下的文件,因此做个笔记。

/**************************************************
boot为文件夹路径,如"D:\\"
***************************************************/
string FileProcess::findFile(string boot) {
	_finddata_t file;
	long lf;
	if ((lf = _findfirst(boot.c_str(), &file)) == -1) {
		cout << "Not found!" << endl;
	}

	else {
		cout << "file name list: " << endl;
		while (_findnext(lf, &file) == 0) {
			if ((strcmp(file.name,".")!=0 && strcmp(file.name,"..")!=0)) {
				cout << file.name << endl;
				return file.name;
			}
		}
	}
	_findclose(lf);
	return "";
}
【上篇】
【下篇】

抱歉!评论已关闭.