c++ 判断文件夹是否存在,并创建文件夹

it2022-05-05  184

<io.h> 函数原型:int _access(const char *pathname, int mode); 参数:pathname 为文件路径或目录路径 mode 为访问权限(在不同系统中可能用不能的宏定义重新定义) 返回值:如果文件具有指定的访问权限,则函数返回0;如果文件不存在或者不能访问指定的权限,则返回-1. 备注:当pathname为文件时,_access函数判断文件是否存在,并判断文件是否可以用mode值指定的模式进行访问。当pathname为目录时,_access只判断指定目录是否存在,在Windows NT和Windows 2000中,所有的目录都只有读写权限。 mode的值和含义如下所示: 0——只检查文件是否存在 2——写权限 4——读权限 6——读写权限

#include<direct.h> mkdir 建立一个文件夹 rmdir 删除一个文件夹 示例代码: #include #include<direct.h> #include<io.h> #include<stdio.h> #include <string.h> using namespace std; void main() { string save_test_mask_ellipse_path = “H:/胎儿超声图像头围测量/test_mask_ellipse”; if (access(save_test_mask_ellipse_path.c_str(), 0) == -1) { mkdir(save_test_mask_ellipse_path.c_str()); //保存文件夹

}

}


最新回复(0)