L o a d i n g . . .
主打一个C++
文章详情

linux中检测目录是否存在或创建目录

Posted on 2024-06-07 07:29:18 by 主打一个C++

参数:目录路径,不存在是否创建(默认false),创建的目录权限(默认读写)

bool IsDirectoryExists(const char* _directoryPath, bool _isCreate=false,mode_t _mode=0755) {
    struct stat st;
    if (stat(_directoryPath, &st) != 0) {
        if (_isCreate) {
            if (mkdir(_directoryPath, _mode) == 0) {
                return true;
            }
            else {
                return false;
            }
        }
    }
    else if (S_ISDIR(st.st_mode)) {
        return true;
    }
    else {
        return false;
    }
    return false;
}


*转载请注明出处:原文链接:https://cpp.vin/page/122.html

作者近期文章
  • 随手笔记
  • 主打一个C++   2025-01-11 20:02:01
  • 都2000000025年了。还有不能随意访问guthub的,仔细看。在国内其实是可以正常访问的,gfw并没屏蔽。这里给出其中一个简单直接的方法稳定访问。1. 随便百度一个”dn
提示
×
确定
数据库执行: 8次 总耗时: 0.01s
页面加载耗时: 



wechat +447752296473
wechat cpp-blog