C语言遍历文件夹里所有文件【转】

 1 #include<iostream>   
 2   #include<string>   
 3   #include<io.h>   
 4   using namespace std; 
 5 
 6   void   filesearch(string path,int layer)   
 7   {   
 8           struct _finddata_t   filefind;   
 9           string  curr=path+"\\*.*";   
10           int   done=0,i,handle;   
11           if((handle=_findfirst(curr.c_str(),&filefind))==-1)
12               return; 
13                 
14           while(!(done=_findnext(handle,&filefind)))   
15           {   
16                       printf("测试的--%s\n",filefind.name);
17                   if(!strcmp(filefind.name,"..")){
18                       
19                           continue;
20                   }
21                   
22                   for(i=0;i<layer;i++)
23                           cout<<"     "; 
24                 
25                 
26                 
27                     
28                   if   ((_A_SUBDIR==filefind.attrib))   
29                   {           
30                               printf("----------%s\n",filefind.name);    
31                           cout<<filefind.name<<"(dir)"<<endl;   
32                           curr=path+"\\"+filefind.name;   
33                          filesearch(curr,layer+1);   
34                   }   
35                   else     
36                   {   
37                           cout<<filefind.name<<endl;   
38                   }   
39           }           
40           _findclose(handle);               
41   }   
42   int   main()   
43   {           
44           string   path;   
45           cout<<"请输入目录"<<endl;   
46           cin>>path;   
47           filesearch(path,0);   
48           system("PAUSE");   
49           return   0;   
50   }   
51   

转载于:https://www.cnblogs.com/freedesert/archive/2012/07/19/2600017.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值