recursive_directory_iterator::increment Method
Increments the iterator and if an error occurs, returns an error_code through an out parameter rather than throwing an exception.
recursive_directory_iterator& increment(error_code& code) noexcept
Parameters
- code
Reference to an error_code variable that you declare and which is filled in by the function with errc::operation_not_permitted if an error occurs.
Return Value
Returns an iterator that points to the next directory_entry.
Exceptions
This function does not throw exceptions.
Remarks
Use this function instead of the ++ operator if you need to avoid exceptions.
Example
The following example iterates through all file system objects under c:\MyData and adds the path string to a vector if the item is a regular file and not a directory.
path p("C:\\MyData");
recursive_directory_iterator it(p), end;
vector<wstring> fileList;
error_code err;
for (it; it != end; it.increment(err))
{
if (err != errc::operation_not_permitted)
{
auto entry = *it;
if (entry.status().type() == file_type::regular)
{
fileList.push_back(entry.path()); //implicit conversion to wstring
}
}
else
{
//handle error
}
}
Requirements
Header: filesystem
Namespace: std::tr2::sys