天狼啸月
天狼神族
posts - 0,  comments - 0,  trackbacks - 0
#include <iostream>
#include 
<string>
#include 
<io.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<fstream>

using namespace std;

int search_dir(string prefix,int i)
{
    ofstream 
in;
    
in.open("a.txt",ios::out);
    
string root = prefix + "*";
    _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;
        i
=search_dir(prefix + data.name + "\\",i);
    }

    
else
    
{
        cout 
<< data.name << endl;
        
in<<data.name<<"\n";
        i
++;
    }


    
while (_findnext(handle, &data) != -1)
    
{
        
if (data.attrib == _A_SUBDIR && strcmp(data.name, "."&& strcmp(data.name, ".."))
        
{
            cout 
<< data.name << endl;
            i
=search_dir(prefix + data.name + "\\",i);
        }

        
else
        
{
            cout 
<< data.name << endl;
            
in<<data.name<<"\n";
            i
++;
        }

    }


    _findclose(handle);
    
return(i);
}



int main()
{
    
int i=0;
    
const string root = "D:\\result1\\";
    i
=search_dir(root,i);
    cout
<<"i="<<i<<endl;
    
return 0;
}

posted on 2011-12-23 09:34 烈焰之光 阅读(113) 评论(0)  编辑 收藏 引用 所属分类: 源码文件及文件夹操作

<2026年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿

文章分类

文章档案

搜索

  •  

最新评论