64,642
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <io.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
void search_dir(string prefix)
{
string root = prefix + "*.txt";
_finddata_t data;
long handle = _findfirst(root.c_str(), &data);
if (handle == -1)
{
cerr << "error" << endl;
exit(1);
}
if (data.attrib == _A_SUBDIR && strcmp(data.name, ".") && strcmp(data.name, ".."))
{
cout << data.name << endl;
search_dir(prefix + data.name + "\\");
}
else
cout << data.name << endl;
while (_findnext(handle, &data) != -1)
{
if (data.attrib == _A_SUBDIR && strcmp(data.name, ".") && strcmp(data.name, ".."))
{
cout << data.name << endl;
search_dir(prefix + data.name + "\\");
}
else
cout << data.name << endl;
}
_findclose(handle);
}
int main()
{
const string root = "C:\\Windows\\";
search_dir(root);
return 0;
}