zoukankan      html  css  js  c++  java
  • c++使用boost库遍历文件夹

    1.只在当前目录下遍历

    #include <boost/filesystem.hpp>
    
    string targetPath="/home/test/target";
    boost::filesystem::path myPath(targetPath);
    boost::filesystem::directory_iterator endIter;
    for (boost::filesystem::directory_iterator iter(myPath); iter != endIter; iter++) {
      if (boost::filesystem::is_directory(*iter)) {
        cout << "is dir" << endl;
        cout << iter->path().string() << endl;
      } else {
        cout << "is a file" << endl;
        cout << iter->path().string() << endl;
      }
    }

    2.在当前目录下递归遍历

    #include <boost/filesystem.hpp>
    
    string targetPath="/home/test/target";
    boost::filesystem::path myPath(targetPath);
    boost::filesystem::recursive_directory_iterator endIter;
    for (boost::filesystem::recursive_directory_iterator iter(myPath); iter != endIter; iter++) {
      if (boost::filesystem::is_directory(*iter)) {
        cout << "is dir" << endl;
        cout << iter->path().string() << endl;
      } else {
        cout << "is a file" << endl;
        cout << iter->path().string() << endl;
      }
    }
  • 相关阅读:
    Go 接口
    Go 参数传递
    Go 结构体
    Go 指针
    使用ContentType处理大量的外键关系
    django的render的特殊用法
    restframework中的那些参数你知道吗?
    scrapy框架
    numpy如何使用
    HTML 5 audio标签
  • 原文地址:https://www.cnblogs.com/sssblog/p/9707734.html
Copyright © 2011-2022 走看看