Search code examples
c++booststliteratordirectory-listing

File system iterator for C++


I'd like a basic C++ STL-like container for the filesystem.

e.g.

std::filesystem::const_iterator i = filesys.begin();  
i->file_name(); i->full_path(), 

etc..

Does something like that exist?


Solution

  • Yes. It exists. Almost similar, atleast which can work with the STL iterators and containers.

    boost::filesystem

    Example:

    path p ("directorypath");
    std::vector<path> v;                      
    std::copy(directory_iterator(p), directory_iterator(), std::back_inserter(v));
    for (std::vector<path>::const_iterator it=v.begin(); it != v.end(); ++it)
    {
         std::cout << "   " << *it << std::endl;
    }
    

    I suppose, now you would like to look at directory_iterator to discover what else it provides.