zoukankan      html  css  js  c++  java
  • VC++读目录下所有文件

    #include   <iostream>  
    #include   <io.h>  
    #include   <direct.h>  
    #include   <string>  
    #include   <vector>  
    #include   <iomanip>  
    #include   <ctime>  
    using   namespace   std;  
    
    void getFiles( string, vector<string>& );
    
    int   main()  {  
        vector<string>   files;  
    
        getFiles( ".", files );
    
         // print the files get
        for   (int   j=0;   j<files.size();   ++j)  {
            cout   <<   files[j] << endl; 
        }
            
        return   0;  
    }
    
    void getFiles( string path, vector<string>& files ) {
        //文件句柄  
        long   hFile   =   0;  
        //文件信息  
        struct _finddata_t fileinfo;  
    
        string p;
    
        if   ((hFile   =   _findfirst(p.assign(path).append("/*").c_str(),&fileinfo))   !=   -1)  {  
    
            do  {  
                //如果是目录,迭代之
                //如果不是,加入列表
                if   ((fileinfo.attrib   &   _A_SUBDIR)) {  
                    if   (strcmp(fileinfo.name,".")   !=   0   &&   strcmp(fileinfo.name,"..")   !=   0)  
                        getFiles(   p.assign(path).append("/").append(fileinfo.name), files   );  
                }  else  {  
                    files.push_back(   p.assign(path).append("/").append(fileinfo.name)  );
                }  
            }   while   (_findnext(   hFile,   &fileinfo   )   ==   0);  
    
            _findclose(hFile);  
        }
    }
  • 相关阅读:
    Ubuntu中的vsftpd配置
    Ubuntu学习-增加更新源及安装软件及卸载软件
    Ubuntu16.04下安装sublime text3
    需要读的书
    同一机器 部署 两个 jboss
    log4j 总结 精华
    oracle 笔记
    oracle 用户 多个表空间
    json
    json 基础
  • 原文地址:https://www.cnblogs.com/jast/p/5021171.html
Copyright © 2011-2022 走看看