• VC中如何创建多层目录


    例如

    gcreatedir("c:\\dir1\\dir2\\dir3");

    如果只需要创建一层目录用 createdirectory 就可以了。
    // create a directory.
    // this function can create a directory under an unexist directory
    // but createdirectory() api cant.
    bool gcreatedir(cstring csdir)
    {
    handle ffile; // file handle
    win32_find_data fileinfo; // file information structure
    cstringarray m_arr; // cstring array to hold directory structures
    bool tt; // bool used to test if create directory was successful
    int x1 = 0; // counter
    cstring tem = ""; // temporary cstring object

    // before we go to a lot of work.
    // does the file exist

    ffile = findfirstfile(csdir,&fileinfo);

    // if the file exists and it is a directory
    if(fileinfo.dwfileattributes == file_attribute_directory)
    {
    // directory exists close file and return
    findclose(ffile);
    return true;
    }

    m_arr.removeall(); // not really necessary - just habit
    for(x1=0;x1<csdir.getlength();x1++) // parse the supplied cstring directory string
    {
    if(csdir.getat(x1) != \\) // if the charachter is not a \
    tem += csdir.getat(x1); // else add character to temp string
    else
    {
    m_arr.add(tem); // if the character is a \ add the temp string to the cstring array
    tem += "\\"; // now add the \ to the temp string
    }
    if(x1 == csdir.getlength()-1) // if we reached the end of the file add the remaining string
    m_arr.add(tem);
    }


    // close the file
    findclose(ffile);

    // now lets cycle through the string array and create each directory in turn
    for(x1 = 1;x1<m_arr.getsize();x1++)
    {
    tem = m_arr.getat(x1);
    tt = createdirectory(tem,null);

    // if the directory exists it will return a false
    if(tt)
    setfileattributes(tem,file_attribute_normal);
    // if we were successful we set the attributes to normal
    }
    m_arr.removeall();
    // now lets see if the directory was successfully created
    ffile = findfirstfile(csdir,&fileinfo);

    // if the file exists and it is a directory
    if(fileinfo.dwfileattributes == file_attribute_directory)
    {
    // directory exists close file and return
    findclose(ffile);
    return true;
    }
    else
    {
    findclose(ffile);
    return false;
    }

    }
  • 相关阅读:
    LNMP源码编译安装(centos7+nginx1.9+mysql5.6+php7)
    linux 最大文件查找
    Nginx 日志分享
    ZendGuardLoader安装
    移动端播放直播流(video.js 播放 m3u8 流)
    Linux下 PostgrelSQL 基本操作
    CenterOS7 安装Mysql8 及安装会遇到的问题
    Linux下 导出postgrelSql 数据库
    《编译程序设计原理与技术》笔记之自动机与正规表达式
    Linux定时检测内存,若使用率超过指标,重启Tomcat并清空内存
  • 原文地址:https://www.cnblogs.com/luoyaoquan/p/2034406.html
Copyright © 2020-2023  润新知