---
title: "C++ 创建文件夹"
author: "Fecoly"
date: "2012-06-28T22:15:51Z"
tags: []
categories: ["编程语言"]
slug: "c"
draft: false
lastmod: "2012-06-29T08:47:22Z"
id: 1570493
url: "https://fecoly.iteye.com/blog/1570493"
---

//C++创建文件夹 
bool CreateFolder(string path) 
{ 
    char* fileName = (char*)path.c_str(); 
    char* tag; 

    for(tag = fileName; *tag; tag++) 
    { 
        if ('\\' == *tag || '/' == *tag) 
        { 
            char buf; 
            char path; 

            strcpy(buf, fileName); 
            buf = '\0'; 
            strcpy(path, buf); 
            if (access(path, 6) == -1) //第二个参数 00:检测是否存在 02:写权限 04:读权限 06:读写权限 
            { 
                mkdir(path); //window 
                //mkdir(path, S_IRWXU); //linux 
            } 
        } 
    } 

    return true; 
}