Reputation: 195
I observe boost (v. 1.64) directory iterator constructor (directory_iterator(const path& p)
) throwing an exception with ERROR_INVALID_DRIVE on a windows system. I suppose the problem happens on NTFS, but can't be 100% sure.
directory_iterator(const path& p)
? From my understanding, it just lists a directory, so can't meke up a way to get an invalid drive hereUPDATE:
Here is the relevant code:
namespace bfs = boost::filesystem;
bfs::path cache_path("C:/Users/Администратор/AppData/Local/some_unique_path/");
long long dir_size = 0;
boost::system::error_code ec;
int err_no = 0;
for (bfs::directory_iterator it(cache_path), eit; it != eit; it.increment(ec)) {
if (ec) {
std::cout << "Error " << 0 << ":" << ec << " while clearing the cache\n";
return;
}
dir_size += bfs::file_size(it->path(), ec);
if (ec) {
std::cout << "Error " << 1 << ":" << ec << " while clearing the cache\n";
return;
}
}
dir_size >>= 20; // want current cache size in Mb
if (dir_size > new_size) {
std::cout << "Clearing the kernel cache..." << std::endl;
// each file is attempted to be removed
for (bfs::directory_iterator it(cache_path), eit; it != eit; ++it) {
if (ec) {
std::cout << "Error " << 2 << ":" << ec << " while clearing the cache\n";
return;
}
bfs::remove(it->path(), ec); // this ec is skipped: don't care if it was impossible to delete file
}
}
Upvotes: 0
Views: 480
Reputation: 70
Would be nice to see a piece of your code. Usually this means that directory does not exist. Be noted that in Windows directory paths have the following format, for example, "C:\dir1\dir2"
. It is hard to help you since you did not provided any source code sample. Maybe you just provided path with wrong format.
Upvotes: 2