参数:目录路径,不存在是否创建(默认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;
}