这次开发中遇到了动态生成路径,如果还能简化,请跟帖,废话不多说,以下是代码:

//创建文件夹,可创建多级文件夹,比如:12/34(当前运行目录)  c:/ab/cd(绝对目录) /ab/cd(当前盘符的根路径)
void CreateDir(const char* pPath);

 

 void CreateDir(const char* pPath)
 {
     if(-1 != access(pPath,0))
         return;

     char tmpPath[MAX_PATH];
     const char* pCur = pPath;

     memset(tmpPath,0,sizeof(tmpPath));
    
     int pos=0;
    while(*pCur++!='\0')
    {
        tmpPath[pos++] = *(pCur-1);

         if(*pCur=='/' || *pCur=='\0')
         {
             if(0!=access(tmpPath,0)&&strlen(tmpPath)>0)
             {
                 mkdir(tmpPath);
             }
         }
     }
 }

windows下要包含#include <direct.h>,linux下自行查找

相关文章:

  • 2022-01-12
  • 2021-12-24
  • 2022-12-23
  • 2021-11-27
  • 2021-06-08
  • 2021-10-14
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2021-08-02
  • 2021-10-23
  • 2021-06-03
  • 2021-09-04
  • 2021-05-31
相关资源
相似解决方案