Created
January 29, 2022 21:01
-
-
Save mikemadden42/913611fc521a90194d31689d3510edb9 to your computer and use it in GitHub Desktop.
Check filesystem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/filesystem.hpp> | |
#include <iostream> | |
// g++ -o boo boo.cc -lboost_filesystem | |
// clang++ -o boo boo.cc -lboost_filesystem | |
int main() { | |
boost::filesystem::path p("/"); | |
auto freeSpace = boost::filesystem::space(p).free; | |
std::cout << freeSpace << " Bytes free" << std::endl; | |
std::cout << freeSpace / (1 << 20) << " MB free" << std::endl; | |
// free space available to a non-privileged process | |
auto availableSpace = boost::filesystem::space(p).available; | |
std::cout << availableSpace << " Bytes available" << std::endl; | |
std::cout << availableSpace / (1 << 20) << " MB available" << std::endl; | |
auto totalSpace = boost::filesystem::space(p).capacity; | |
std::cout << totalSpace << " Bytes capacity" << std::endl; | |
std::cout << totalSpace / (1 << 20) << " MB capacity" << std::endl; | |
auto usedSpace = totalSpace - freeSpace; | |
std::cout << usedSpace << " Bytes used" << std::endl; | |
std::cout << usedSpace / (1 << 20) << " MB used" << std::endl; | |
auto usedPercent = static_cast<double>(usedSpace) / static_cast<double>(totalSpace); | |
std::cout << usedPercent << " percent used" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment