说明
access
函数判断文件夹或者文件是否存在
函数原型
int access(const char *filename, int mode);
所属头文件: io.h
参数:
filename:可以填写文件夹路径或者文件路径
mode:有以下值:
- 0 (F_OK) 只判断是否存在
- 2 (R_OK) 判断写入权限
- 4 (W_OK) 判断读取权限
- 6 (X_OK) 判断执行权限
mode 取值说明:
用于判断文件夹是否存在的时候,mode取
0
判断文件是否存在的时候,mode可以取
0、2、4、6
。
若存在或者具有权限,返回值为0
;不存在或者无权限,返回值为-1
。
例子
#include <stdio.h>
#include <io.h>
int main(void)
{
if ( !access("C://windows",0) )
puts("C://windows EXISITS!");
else
puts("C://windows DOESN'T EXISIT!");
return 0;
}
参考:
https://blog.csdn.net/weixin_44981971/article/details/121662995
https://blog.csdn.net/xhhjin/article/details/6369336