如何(使用提高文件系统库)来获取文件名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());