On Windows, this is true, but I found Ubuntu on which the iterator becomes invalid after uninstall, so the next access throws an exception.
So, I used something like this:
recursive_directory_iterator end; for (recursive_directory_iterator itr(folderPath); itr != end; ) { path filePath = *itr++; if (is_regular_file(filePath) && filePath.string().find(filter) != std::string::npos) { if (remove(filePath)) { removedFilesCounter++; } } }
kenny mccormick
source share