#include#include namespace fs = boost::filesystem; int main() { fs::path dir_path("/usr/bin"); if(fs::exists(dir_path) && fs::is_directory(dir_path)) { std::cout << dir_path << " exists and is a directory" << std::endl; } else { std::cout << dir_path << " does not exist" << std::endl; } return 0; }
#include#include namespace fs = boost::filesystem; int main() { fs::path dir_path("/usr/bin"); if (fs::exists(dir_path) && fs::is_directory(dir_path)) { for(fs::directory_entry& entry : fs::directory_iterator(dir_path)) { std::cout << entry << std::endl; } } return 0; }
#includeIn the above example, we are renaming a file. To use the cpp boost.filesystem path extension, we need to include the#include namespace fs = boost::filesystem; int main() { fs::path old_path("/usr/bin/hello.txt"); fs::path new_path("/usr/bin/goodbye.txt"); if (fs::exists(old_path)) { fs::rename(old_path, new_path); } return 0; }