c++创建文件夹

创建文件夹:

1.include

string path="./xx/xxx.txt"

FILE fp=fopen(path.c_str(),"r");

if (fp=NULL){

    _mkdir(path.c_str())

}

2.采用system,即调用dos命令

system("md ./xx/xxx.txt");其中这个字符串可以用相加,也可以sprintf(make_filepath,"md %s",path.c_str());system(make_filepath)

也有的是"mkdir -p ./xx/xxx.txt"

3.采用WIN API函数#include

if (!GetFileAttributesA("./xx/xxx.txt") & FILE_ATTRIBUTE_DIRECTORY) //检查

       { bool flag = CreateDirectory(folderPath.c_str(), NULL);}//创建并返回是否成功

4.#include   //MFC的封装接口

if (!PathIsDirectory(folderPath.c_str()))

{ ::CreateDirectory(folderPath.c_str(), 0);}

5.#include

if (0 != access("./xx/xxx.txt", 0))

{ mkdir("./xx/xxx.txt"); }

你可能感兴趣的:(C++)