这里记录下如何使用boost创建文件夹的方法。
主要步骤
- 包含filesystem头文件
#include <boost/filesystem.hpp>
- 检测传入的文件目录(log_path)是否存在,目录不存在的话会新建一个目录
boost::filesystem::path dir = log_path;
boost::system::error_code error;
auto file_status = boost::filesystem::status(dir, error);
if(error){
std::cout << "file status error" << std::endl;
}
if(!boost::filesystem::exists(file_status)){
std::cout << "file exist error" << std::endl;
boost::filesystem::create_directories(dir);
}