专栏中心

EEPW首页 > 专栏 > linux下的access()函数判断文件是否存在

linux下的access()函数判断文件是否存在

发布人:电子禅石 时间:2021-08-11 来源:工程师 发布文章
#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


专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们

关键词: C
更多 培训课堂
更多 焦点
更多 视频

技术专区