I made a forum post ([Filesystem] remove and recursive_directory_iterator) on
http://news.gmane.org/gmane.comp.lib.boost.user[
^]. Not sure if it is a 'feature'. Turning the for loop into while and increment iterator before remove does the trick for me:
fs::recursive_directory_iterator it(pthDirectory);
fs::recursive_directory_iterator itEnd;
while (it != itEnd)
{
boost::system::error_code ec;
const fs::path& rPath = it->path();
if (fs::is_directory(rPath, ec) && fs::is_empty(rPath, ec))
{
const fs::path pth = rPath;
++it;
fs::remove(pth, ec);
}
else
{
++it;
}
}