简体   繁体   English

C ++ boost :: filesystem如何检测路径是文件还是目录?

[英]How C++ boost::filesystem detect if path is file or directory?

In boost::filesystem library is there any way to determine if the path is directory or file? 在boost :: filesystem库中,有什么方法可以确定路径是目录还是文件?

My scenario is : I have some folders and files which i need full path of the all files and push it to vector, so i did this : 我的情况是:我有一些文件夹和文件,我需要所有文件的完整路径并将其推送到vector,所以我这样做了:

for ( boost::filesystem::recursive_directory_iterator end, dir(pathBase);
    dir != end; ++dir ) {
    if ( boost::filesystem::exists( dir->path() ) )
    {
        std::cout << dir->path() << "\n";  // full path
        filenames.push_back(dir->path().string());
    }
  }

The problem is the exists method check if directory or file exist and could not detect their type(file or directory). 问题是exists方法检查目录或文件是否存在并且无法检测到它们的类型(文件或目录)。

So how can i get only files with boost library? 那么我怎样才能只获得带有Boost库的文件?

听起来您需要boost::filesystem::is_regular_file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C++:在比较 boost::filesystem 中的路径时如何忽略第一个目录路径? - C++: How do I ignore the first directory path when comparing paths in boost::filesystem? 如何在c ++中获取文件名与目录名(使用boost文件系统库) - how to get file names vs directory names in c++ (using boost filesystem library) C ++ Boost Filesystem:如何修改路径中的词干? - C++ Boost Filesystem: How to modify stem from a path? C ++ Boost :: filesystem ::具有Unicode字符的路径 - C++ Boost::filesystem::path with unicode characters 如果路径是可创建的文件,如何使用 boost::filesystem 检查? - How to check with boost::filesystem if a path is a creatable file? Boost.Filesystem 和 C++ 标准文件系统库有多相似? - How similar are Boost.Filesystem and the C++ standard filesystem library? c ++ boost :: filesystem undefined对`boost :: filesystem3 :: path :: root_name()const&#39;的引用 - c++ boost::filesystem undefined reference to `boost::filesystem3::path::root_name() const' 可变字符串的BOOST文件系统路径 - c++ - BOOST filesystem path from variable string 使用boost :: filesystem :: path作为参数的C ++构造函数调用-没有任何反应 - C++ constructor call with boost::filesystem::path as argument - nothing happening 用C ++解释boost :: filesystem的可移植通用路径格式 - Explain boost::filesystem's portable generic path format in C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM