c++循环创建文件夹

#include <iostream>
#include<direct.h>
#include<io.h>

bool CheckPathExist(std::string path)
{
    if (access(path.c_str(), 0) == -1)
    {
        return false;
    }
    return true;
}

void CreateDir(std::string filepath)
{
    std::string::size_type tmp_pos_begin = 0;
    std::string::size_type tmp_pos = 0;
    tmp_pos = filepath.find('/', tmp_pos_begin);
    while (tmp_pos != filepath.npos)
    {
        std::string tmpdir = filepath.substr(0, tmp_pos);
        if (tmpdir.empty())
        {
            return;
        }
        if (!CheckPathExist(tmpdir))
        {
            _mkdir(tmpdir.c_str());
        }
        tmp_pos_begin = tmp_pos + 1;
        tmp_pos = filepath.find('/', tmp_pos_begin);
    }
}
int main()
{
    CreateDir("./aaa/bbb/ccc/ddd/ff/");
    std::cout << "Hello World!\n";
}

 

posted @ 2022-03-18 16:18  leochan007  阅读(338)  评论(0编辑  收藏  举报