c++ 判断文件夹是否存在,不存在则创建 (linux c 判断文件夹是否为空)

c++中,中的_access可以判断文件是否存在,中的_mkdir可以岩闹尺创建文件。

—-

建单级目录:

#include

#include

#include

int main()

{

std::string prefix = “弯芦G:/test/”;

if (_access(prefix.

c_str

(), 0) == -1) //如果

文件夹

不存在

_mkdir(prefix.c_str()); //则创建

}

建多级目录:

最后一个如果是文件夹的话,需要加上 ‘\\’ 或者 ‘/粗高’

#include

#include

#include

int createDirectory(std::string path)

{

int len = path.length();

char tmpDirPath = { 0 };

for (int i = 0; i

{

tmpDirPath = path;

if (tmpDirPath == ‘\\’ || tmpDirPath == ‘/’)

{

if (_access(tmpDirPath, 0) == -1)

{

int ret = _mkdir(tmpDirPath);

if (ret == -1) return ret;

}

}

}

return 0;

相关问题拓展阅读:

linux脚本开发-关于压缩文件脚本的判断修改

你可以判断文件是否为空,如果为空不慧旦则压缩,如前棚果不为空则可以压缩,,if >

then

ok

fi你迟森自己把代码再改改..

关于linux c 判断文件夹是否为空的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。


数据运维技术 » c++ 判断文件夹是否存在,不存在则创建 (linux c 判断文件夹是否为空)