遍历文件夹下文件

 #include<iostream> #include<string> #include<io.h> using namespace std; void filesearch(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))) { if(!strcmp(filefind.name,".."))continue; for(i=0;i<layer;i++)cout<<" "; if ((_A_SUBDIR==filefind.attrib)) { cout<<filefind.name<<"(dir)"<<endl; curr=path+"//"+filefind.name; filesearch(curr,layer+1); } else { cout<<filefind.name<<endl; } } _findclose(handle); } int main() { filesearch("E://Program Files//",0); system("PAUSE"); return 0; }

你可能感兴趣的:(String,struct,System,Path,layer)