Knotwood V
Knotwood V

Reputation: 51

c++ Boost if .extension() == "" this would mean this file is a folder?

I just want to confirm that this would be a good method to allow me to only work only on folders, as i can see a way to just look for folder rather that files and folders .

boost::filesystem::directory_iterator iterator(string("."));
for (; iterator != boost::filesystem::directory_iterator(); ++iterator)
{
    if ((iterator->path().extension()) == "") { 
        cout << (iterator->path().stem()) <<   endl; 
    };
}

Upvotes: 2

Views: 811

Answers (1)

lisyarus
lisyarus

Reputation: 15522

Files can exist without any extension, so this won't work.

Have a look at boost::filesystem::is_directory.


By the way, Boost.Filesystem library was merged into C++17 standard. So, if your compiler supports C++17, consider using the standard library for filesystem operations.

Upvotes: 10

Related Questions