64,637
社区成员
发帖
与我相关
我的任务
分享
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/progress.hpp"
#include <iostream>
#include <string>
#include <exception>
#include <vector>
namespace fs = boost::filesystem;
const size_t GB = 1<<30;
int main( int argc, char* argv[] )
{
std::string path(" :");
std::cout << "Windows:\n盘符\t" << "总空间\t\t" << "可用空间\t" << std::endl;
for (char ch='a'; ch<='z'; ++ch){
path[0] = ch;
fs::path p(path);
try {
if (!fs::exists(p)) continue;
std::cout << path << '\t';
fs::space_info si = fs::space(p);
std::cout<< si.capacity * 1.0 / GB << "GB\t"
<< si.available * 1.0 / GB << "GB\t"
<< std::endl;
}
catch (const std::exception& e) {
std::cout << e.what()<< std::endl;
}
}
return 0;
}