最近做个项目需要侦听某个文件夹下有无文件,如果有则处理该文件,如果没有继续等待,因此需要读取文件夹下的文件,因此做个笔记。
/**************************************************
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 "";
}