Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 281
unixman83 Avatar asked Feb 25 '23 12:02

unixman83


2 Answers

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.

like image 149
Nawaz Avatar answered Feb 27 '23 02:02

Nawaz


Another one is STLSOFT platformstl::readdir_sequence.

Example provided here

like image 23
Sergei Nikulov Avatar answered Feb 27 '23 03:02

Sergei Nikulov