我观察到 boost (v. 1.64) 目录迭代器构造函数 (directory_iterator(const path& p)
) 在 Windows 系统上抛出 ERROR_INVALID_DRIVE 异常。我想问题发生在 NTFS 上,但不能 100% 确定。
- ERROR_INVALID_DRIVE 的一般原因是什么?
- 什么可能将其放入
directory_iterator(const path& p)
中?据我了解,它只是列出了一个目录,因此无法在此处找到获取无效驱动器的方法
更新:
相关代码如下:
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
}
}
最佳答案
很高兴看到您的一段代码。通常这意味着该目录不存在。请注意,在 Windows 中,目录路径具有以下格式,例如,"C:\dir1\dir2"
。由于您没有提供任何源代码示例,因此很难为您提供帮助。也许您只是提供了错误格式的路径。
关于c++ - boost 目录迭代器抛出 ERROR_INVALID_DRIVE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57005825/