C++ 遍历文件夹

来源:互联网 发布:2017成都软件行业 编辑:程序博客网 时间:2024/06/01 08:32
#include<iostream>     
#include<string>     
#include<io.h>

using namespace std;


void sadsadsa(std::string path, int layer)
{
struct _finddata_t filefind;
string  curr = path + "\\*.*";
int   done = 0, i, handle;
if ((handle = _findfirst(curr.c_str(), &filefind)) == -1)return;
while (!(done = _findnext(handle, &filefind)))
{
printf("%s\n", filefind.name);
if (!strcmp(filefind.name, "..")){
continue;
}
for (i = 0; i<layer; i++)cout << "     ";
if ((_A_SUBDIR == filefind.attrib)) //是目录  
{
printf("----------%s\n", filefind.name);
cout << filefind.name << "(dir)" << endl;
curr = path + "\\" + filefind.name;
}
else//不是目录,是文件       
{
cout << path + "\\" + filefind.name << endl;
}
}
_findclose(handle);
}




0 0
原创粉丝点击