zoukankan      html  css  js  c++  java
  • 创建文件目录

    创建文件目录

    主要在windows系统下测试使用

    1,使用CreateDirectory

    创建单级目录

    CreateDirectory("C:\abc", NULL);//使用绝对路径创建文件夹
     
    递归创建多级目录
    int index, start = 0;
    CString strTmp;
    CString strPath = "E:\aaa\bbb\ccc\ddd";

    while ( (index = strPath.Find('\', start)) != -1) {
            strTmp = strPath.Left(index);

            CreateDirectory(strTmp, NULL);

            start = index + 1;      
    }
     
    2,使用MakeSureDirectoryPathExists

    函数功能描述:该函数创建一个从根目录开始的完整的指定路径.

    函数原型:
     BOOL MakeSureDirectoryPathExists(PCSTR DirPath);

    参数:
    DirPath [in] : 指向一个以NULL结尾的包含正确的指定的路径名,如果路径名的结尾部分不是文件名而是文件夹,那么要以'/'为结束符.
    返回值:函数成功返回TRUE; 函数失败返回FALSE;要获得具体错误信息用GetLastError();
    备注: 每一级目录如果不存在就创建它,如果只有一些目录被创建了,那么函数返回FALSE.

    示例代码段:
    在用MakeSureDirectoryPathExists前,要在Project->Settings...->Link->/Object/library modules中加入imagehlp.lib.

    具体函数如下:
    {
      BOOL bRet=MakeSureDirectoryPathExists("f://Directory1//Directory2//Directory3//");
      //创建目录,要注意结尾"//",否则会失败.
      ASSERT(bRet);
      bRet=MakeSureDirectoryPathExists("f://Directory1//Directory2//Directory3");
      //创建目录,但不创建Directory3,因为没有'//'结尾.
        ASSERT(bRet);
          bRet=MakeSureDirectoryPathExists("f://Directory1//Directory2//Directory3//test.txt");
          //创建目录,但不创建文件,可以不用'//'结尾.
          ASSERT(bRet);
    }
    注意包含头文件及相应库文件
    头文件: 在Dbghelp.h中定义.
    静态库: Dbghelp.lib.

    3,使用windows下的bat脚本函数 mkdir
    system("mkdir  "E:\aaa\bbb\ccc\ddd"");
  • 相关阅读:
    Python进阶(二)
    python基础(四)
    Python基础(三)
    python基础(二)
    Python基础(一)
    backbone之extend方法(刚明白了点)
    js中url相关
    bootstrap导航、导航条及导航翻页相关详解
    bootstrap中css组件(除导航条)
    bootstrap基础排版优化
  • 原文地址:https://www.cnblogs.com/widget90/p/5606413.html
Copyright © 2011-2022 走看看