开发者

File system iterator for C++

开发者 https://www.devze.com 2023-02-25 21:46 出处:网络
I\'d like a basic C++ STL-like container for the filesystem. e.g. 开发者_高级运维 std::filesystem::const_iterator i = filesys.begin();

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?


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.


Another one is STLSOFT platformstl::readdir_sequence.

Example provided here


I believe the boost::filesystem library has this functionality.


Visual C++ 2012 has something now. See C++11 filesystem (VS2012). Also http://msdn.microsoft.com/en-us/library/hh874694.aspx for the VS2013 implementation.

0

精彩评论

暂无评论...
验证码 换一张
取 消