如何(使用提高文件系统库)来获取文件名VS在C ++中的目录名 [英] how to get file names vs directory names in c++ (using boost filesystem library)

查看:285
本文介绍了如何(使用提高文件系统库)来获取文件名VS在C ++中的目录名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用的boost ::文件系统来得到一个目录下的文件名列表,我收到文件名以及目录名称:

When I use boost::filesystem to get a list of file names in a directory, I receive file names as well as directory names:

#include <string>
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;

int main()
{
    path p("D:/AnyFolder");
    for (auto i = directory_iterator(p); i != directory_iterator(); i++)
    {
        cout << i->path().filename().string() << endl;
    }
}

输出是这样的:

file1.txt
file2.dat
Folder1 //which is a folder

有没有快捷方式文件和文件夹之间的区别?
我的操作系统是Windows 8.1,如果它很重要。

Is there a quick way to distinguish between files and folders? My OS is Windows 8.1, if it matters.

推荐答案

is_directory()

boost::filesystem::is_directory(i->path());

这篇关于如何(使用提高文件系统库)来获取文件名VS在C ++中的目录名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆