VC确保存路径存在在,如果不存在则创建

作者: 吴杰 分类: 编程 发布时间: 2015-10-13 20:31
void MakeSureDirExist(const char * pPath )
{
        if ( pPath == NULL)
               return;
       std:: string strPath( pPath);
       
        if (strPath.at(strPath.length() - 1) != '\\')
              strPath += '\\';

        int len = strPath.length();
        for( int i =0; i < len; ++i)
       {
               if(strPath[i]== '\\')
              {
                     :: CreateDirectory((strPath.substr(0, i)).c_str(), NULL );
              }
       }

}