分享

c++ 递归创建目录

 勤奋不止 2013-08-26
#include <direct.h>
#include <string>

void main()
{
    string targetPath = "c:\\1\\2\\3\\";
    CheckTargetPath(targetPath);
}

//if the directory is not existing, creat it
void CheckTargetPath(string targetPath)
{
    //Log &log = Log::getLog("main", "CheckTargetPath");
    int e_pos = targetPath.length();
    int f_pos = targetPath.find("\\",0);
    string subdir;
    do
    {
        e_pos = targetPath.find("\\",f_pos+2);
        if(e_pos != -1)
        {
            subdir = targetPath.substr(0,e_pos);
            if(_mkdir(subdir.c_str())==0)
 //               log.debug( "creat success %s",subdir.c_str());
 //           else log.debug("creat fail %s",subdir.c_str());
        }
        f_pos = e_pos;
    }while(f_pos!=-1);
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约