c++17 filesystem 创建目录

创建日期: 2024-10-24 13:05 | 作者: 风波 | 浏览次数: 16 | 分类: C++

来源:https://stackoverflow.com/questions/71658440/c17-create-directories-automatically-given-a-file-path

#include <string>
#include <filesystem>

// Returns:
//   true upon success.
//   false upon failure, and set the std::error_code & err accordingly.
bool CreateDirectoryRecursive(std::string const & dirName, std::error_code & err)
{
    err.clear();
    if (!std::filesystem::create_directories(dirName, err))
    {
        if (std::filesystem::exists(dirName))
        {
            // The folder already exists:
            err.clear();
            return true;    
        }
        return false;
    }
    return true;
}
16 浏览
12 爬虫
0 评论