Vladimir Nazarenko
Vladimir Nazarenko

Reputation: 195

Boost directory iterator throwing ERROR_INVALID_DRIVE

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.

  1. What are general reasons for ERROR_INVALID_DRIVE?
  2. What may be throwing it inside 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 here

UPDATE:

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

Answers (1)

Cactus&#39;as
Cactus&#39;as

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

Related Questions