代码
vector<string> findfile(string path, string mode)
{
vector<string> files;
_finddata_t file;
intptr_t HANDLE;
string Onepath = path + mode;
HANDLE = _findfirst(Onepath.c_str(), &file);
if (HANDLE == -1L)
{
cout << "can not match the folder path" << endl;
system("pause");
}
do {
//判断是否有子目录
if (file.attrib & _A_SUBDIR)
{
//判断是否为"."当前目录,".."上一层目录
if ((strcmp(file.name, ".") != 0) && (strcmp(file.name, "..") != 0))
{
string newPath = path + "\\" + file.name;
findfile(newPath, mode);
}
}
else
{
cout << file.name << " " << endl;
files.push_back(file.name);
}
} while (_findnext(HANDLE, &file) == 0);
_findclose(HANDLE);
return files;
}
之前试了好多别的博客的代码,怎么都不行,这个可以!