新闻  |   论坛  |   博客  |   在线研讨会
linux下的access()函数判断文件是否存在
电子禅石 | 2021-08-11 17:10:34    阅读:1487   发布文章

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{    if((access("test.c",F_OK))!=-1)
    {
        printf("文件 test.c 存在.\n");
    }    else
    {
        printf("test.c 不存在!\n");
    }    if(access("test.c",R_OK)!=-1)
    {
        printf("test.c 有可读权限\n");
    }    else
    {
        printf("test.c 不可读.\n");
    }    if(access("test.c",W_OK)!=-1)
    {
        printf("test.c 有可写权限\n");
    }    else
    {
        printf("test.c 不可写.\n");
    }    if(access("test.c",X_OK)!=-1)
    {
        printf("test.c 有可执行权限\n");
    }    else
    {
        printf("test.c 不可执行.\n");
    }    return 0;
}

转载于:https://www.cnblogs.com/liwentao1091/p/4040154.html


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
属于自己的技术积累分享,成为嵌入式系统研发高手。
推荐文章
最近访客